Question:
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:
1 2 3 4 5 6 7 8 9 10 11 12 |
#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:
1 2 3 4 5 6 |
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. |
Answer:
Ok! Turns out the solution is as follows (in case this shows up in a search result):
- Add Directory:
C:\Temp
- Add Directory:
C:\Windows\SysWOW64\config\systemprofile\Desktop
That should fix the problem.