I am using PowerShell to unlock a locked Excel spreadsheet. When I run the script from a job (using myself as the Proxy user), the Excel portion of the script does not run. When I execute the same script directly from the command line, however, it works fine. My code is:
#Unlock Attatchment
$x = New-Object -comObject Excel.Application
$x.visible = $false
$x.DisplayAlerts = $False
$workbook = $x.Workbooks.Open($spreadsheetFileName,1,$false,
5,$spreadsheetPassword,$spreadsheetPassword)
$workbook.SaveAs($tmpFileName,1,$null,$null,$null,$null,$null,
$x.XlSaveConflictResolution.xlLocalSessionChanges,
$null,$null,$null,$null)
$x.Workbooks.Close()
$x.Quit()
Edit: I added logging. Here are the log results:
Exception calling "Open" with "6" argument(s): Microsoft Office Excel cannot access the file "_____"
There are several possible reasons:
• The file name or path does not exist.
• The file is being used by another program.
• The workbook you are trying to save has the same name as a currently open workbook.
Ok! Turns out the solution is as follows (in case this shows up in a search result):
C:\Temp
C:\Windows\SysWOW64\config\systemprofile\Desktop
That should fix the problem.
For Windows 2012 x64 I also had to create the folder below before it worked.
C:\Windows\System32\config\systemprofile\Desktop
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With