Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

MS Access 2010, Excel 2010, Windows Server 2008 R2 64-bit: SaveAs method of Workbook class failed

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.

like image 906
user5239568 Avatar asked Dec 02 '25 16:12

user5239568


1 Answers

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
like image 50
user5239568 Avatar answered Dec 04 '25 09:12

user5239568