I have an Access database that calls a sub in Excel and runs it perfectly. Then it flicks back to access, asks a question and then, depending upon the answer of that, should call a second sub in the same Excel spreadsheet that was already open.
Both subs in Excel are 'public' and both sit under "thisworkbook' and I definitely have the name of the second sub correct.
Access code is below. (xlApp is earlier defined by
Set xlApp = CreateObject("Excel.Application")
I get a run-time error 424 "object required" when I hit the second .run MacroName line.
With xlApp
.Visible = True
.Workbooks.Open progsPathName & "excel_for_plots.xlsm"
MacroName = .ActiveWorkbook.Name & "!" & "ThisWorkbook.do_the_country_stuff"
.Run MacroName
' check the labels
m = MsgBox("Are the labels ok?", vbYesNo, "Label positions")
If m = vbNo Then
MacroName = .ActiveWorkbook.Name & "!" & "ThisWorkbook.first_check"
.Run MacroName
End If
End With
I have tried checking the sub names, checking they are public, calling the sub something different, using the immediate window to check the 2 MacroName strings are the same except for the sub names. I always get the same error.
ugh, I knew that would happen as soon as I posted! So it seems that the error was actually within the excel sub that was being called. When I hit debug it only highlighted the access line that was calling the excel sub but it was the excel sub that required the object.
Leaving this up incase it helps someone else as I've spent ages trying to work out what my access problem was, not my excel one.