romeerome368
Programmer
Hello Everyone,
I have an Access 2007 database that I generate reports in Excel. The data in the database gets refreshed everyday at 5 am in the morning, and I have a scheduled task that runs the refresh of my backend database, and a task that refreshs my Excel spreadsheet as well. My code stops working on the refreshall command that is in my VBA code. I checked my Excel VBA references, and they are all checked without anything MISSING. Also, I know that the simple thing to do would be to have the spreadsheet to refresh upon opening, but I don't want it to do that everytime since this is a snapshot of data that I am providing, therefore I am doing through VBA.
Below is a sample of my code:
Public Sub UpDateExcel()
Dim xlApp As Excel.Application
Dim xlWorkbook As Excel.Workbook
Dim xlSheet As Excel.Worksheet
Dim x As Variant
Set xlApp = CreateObject("Excel.Application")
xlApp.DisplayAlerts = False
xlApp.Visible = True
xlApp.Workbooks.Open ("C:\Filename.XLS")
xlApp.ActiveWorkbook.RefreshAll
xlApp.Range("C8").Select
x = xlApp.Range("C8").Value
x = x + 1
xlApp.ActiveCell.Value = x
xlApp.ActiveWorkbook.Save
xlApp.ActiveWorkbook.Close
xlApp.Quit
Set xlApp = Nothing
Set xlWorkbook = Nothing
Set xlSheet = Nothing
Set x = Nothing
End Sub
Everytime I run my VBA from Access, I get the error message below.
Runtime Error '1004':
Method 'RefreshAll" of object '_Workbook' failed
I know this code should work, but please let me know if I'm missing something.
Thanking you in advance for your assistance.
I have an Access 2007 database that I generate reports in Excel. The data in the database gets refreshed everyday at 5 am in the morning, and I have a scheduled task that runs the refresh of my backend database, and a task that refreshs my Excel spreadsheet as well. My code stops working on the refreshall command that is in my VBA code. I checked my Excel VBA references, and they are all checked without anything MISSING. Also, I know that the simple thing to do would be to have the spreadsheet to refresh upon opening, but I don't want it to do that everytime since this is a snapshot of data that I am providing, therefore I am doing through VBA.
Below is a sample of my code:
Public Sub UpDateExcel()
Dim xlApp As Excel.Application
Dim xlWorkbook As Excel.Workbook
Dim xlSheet As Excel.Worksheet
Dim x As Variant
Set xlApp = CreateObject("Excel.Application")
xlApp.DisplayAlerts = False
xlApp.Visible = True
xlApp.Workbooks.Open ("C:\Filename.XLS")
xlApp.ActiveWorkbook.RefreshAll
xlApp.Range("C8").Select
x = xlApp.Range("C8").Value
x = x + 1
xlApp.ActiveCell.Value = x
xlApp.ActiveWorkbook.Save
xlApp.ActiveWorkbook.Close
xlApp.Quit
Set xlApp = Nothing
Set xlWorkbook = Nothing
Set xlSheet = Nothing
Set x = Nothing
End Sub
Everytime I run my VBA from Access, I get the error message below.
Runtime Error '1004':
Method 'RefreshAll" of object '_Workbook' failed
I know this code should work, but please let me know if I'm missing something.
Thanking you in advance for your assistance.