Services used: MS Access 2010, Excel 2010, Windows Server 2008 R2 (64-bit)
In our MS Access database, we wrote a process that exports queries to .xlsx format and saves them on the network drive. It uses this syntax:
objxl.ActiveWorkbook.SaveAs filename, FileFormat:=xlOpenXMLWorkbook
and
xlWBk.SaveAs filename, FileFormat:=xlOpenXMLWorkbook
where objxl is declared as:
Private objxl As Object
And files are opened via:
Dim xlWBk As Object
If objxl Is Nothing Then
Set objxl = CreateObject("Excel.Application")
End If
If Dir(sourceFile) = vbNullString Then
Set xlWBk = objxl.Workbooks.Add
Else
Set xlWBk = objxl.Workbooks.Open(sourceFile)
blnFileExists = True
End If
This code works fine when we run it manually. I am reasonably confident that the code is correct, but I'm posting it here just in case.
However, we need to automate this database so we have it run from an account via scheduled task, set to run even if the account is not logged in (and this account has admin rights, etc). Unfortunately, when running the program like this, we get this error in our logs:
"SaveAs method of Workbook class failed."
We've verified that it isn't a network read/write problem (it writes all sorts of other files, such as .txt and .pdf, just fine to the network drive. This issue appears to be localized to Excel).
We've tried a fix as per this post: https://stackoverflow.com/a/1090864/5239568
But nothing seems to be working so far.
Finally got it fixed. Here was what worked, in case anyone in the future has this same error.
We added BOTH folders:
C:\Windows\System32\config\systemprofile\Desktop
C:\Windows\SysWOW64\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