title: Open Excel and pass file password through
body: <p>I have some excel files that I refresh nightly </p>
  
  <p>I now want to password protect them in order to modify any data from them, but when the script opens the file it prompts for the password, </p>
  
  <p>how do i pass the password with script?</p>
  
  <p>heres what i use(have tried)</p>
  
  <pre><code>Set fs = CreateObject("Scripting.FileSystemObject")
   Set rootFolder = fs.GetFolder(fs.GetParentFolderName(wscript.ScriptFullName))
  Set oExcel = CreateObject("Excel.Application")
  
   oExcel.Visible = True
   oExcel.DisplayAlerts = False
   oExcel.AskToUpdateLinks = False
   oExcel.AlertBeforeOverwriting = False
  
   For Each file in rootFolder.Files
     If inStr(file.type, "Script") = 0 Then
       Set oWorkbook = oExcel.Workbooks.Open(file.path)
  
  Dim WSH
  Set WSH = CreateObject("WScript.Shell")
  wsh.sleep(25000)
  Wsh.SendKeys "?"
  Wsh.SendKeys "{ENTER}"  
  
       oWorkbook.RefreshAll
       oWorkbook.Save
       oWorkbook.Close
       Set oWorkbook = Nothing
    End If
   Next
  
   oExcel.Quit
  set oExcel = nothing
  </code></pre>
  
  <p>any help? i dont really use vbs much(at all) </p>
  
  <p>edit, this code works in opening the file refreshing all, saving then closing, i just dont know how to get it to input the pass word in order to open it in full edit mode</p>
  
  <pre><code>Set fs = CreateObject("Scripting.FileSystemObject")
   Set rootFolder = fs.GetFolder(fs.GetParentFolderName(wscript.ScriptFullName))
  Set oExcel = CreateObject("Excel.Application")
  
   oExcel.Visible = True
   oExcel.DisplayAlerts = False
   oExcel.AskToUpdateLinks = False
   oExcel.AlertBeforeOverwriting = False
  
  
   For Each file in rootFolder.Files
     If inStr(file.type, "Script") = 0 Then
       Set oWorkbook = oExcel.Workbooks.Open(file.Path)
  
       oWorkbook.RefreshAll
       oWorkbook.Save
       oWorkbook.Close
       Set oWorkbook = Nothing
    End If
   Next
  
   oExcel.Quit
  set oExcel = nothing
  </code></pre>