How do I update the .Application
properties in an Excel workbook from Access VBA?
I'm using Access VBA to export data to Excel, open the file, and format the file (add formulas, etc.).
The code is slow. I want to disable screen updates and change Excel calculations to manual.
.ScreenUpdating = false
doesn't produce run-time errors, but the screen updates as if the code is ignored.
.Application.Calculation
produces a run-time error 1004.
Dim Xl As Excel.Application
Dim XlBook As Excel.Workbook
Set Xl = CreateObject("Excel.Application")
Set XlBook = GetObject(Forms!Main!Final_filepath)
XlBook.Activate
XlBook.Windows(1).Visible = True
'Hide alerts to prevent interruptions when running code
Xl.Application.DisplayAlerts = False '<---- No errors
Xl.Application.ScreenUpdating = False '<---- No errors, but screen updating isn't disabled.
Xl.Application.Calculation = xlCalculationManual '<---- Run-Time Error 1004
Xl
is anExcel.Application
(and the code compiles), thenXl.Application
is redundant. DoesXl.ScreenUpdating = False
work any better? (not expecting it to, sinceXl.Application
should just point right back at theXl
object) – Mathieu GuindonSet Xl = CreateObject("Excel.Application")
is a rather roundabout way to doSet Xl = New Excel.Application
(again, not the problem, just pointing it out) – Mathieu GuindonExcel.Application
instance, and yetXlBook
is being assigned just fine...GetObject
seems a weird way to do this.Set XlBook = Xl.Workbooks.Open(Forms!Main!Final_filepath)
would be simpler, it seems. – Mathieu GuindonExcel.Application
instance being created by accident somewhere, somehow (it's very easy to do! simply forget aXl.
qualifier somewhere and boom, implicit app reference, and ghost EXCEL.EXE process lingering in Task Manager well after the macro completed). – Mathieu Guindon