I've been struggling with this problem for the last few hours and tried multiple solutions to no avail. I'm trying to open an excel 2016 (64-bit) report in MS Access, the default excel is 2003 and must stay that way for now. My code is:
Dim xlTmp As excel.Application
Shell ("C:\Program Files\Microsoft Office\root\Office16\EXCEL.exe")
Set xlTmp = GetObject(, "Excel.Application")
This code does exactly what I want only when I am stepping through in debug mode, because excel doesnt fully start up before it tries to grab the object. If run normally it throws up an error:
Run-Time error '429' ActiveX component can't create object
I've tried some of the following solutions to no avail:
Function OpenExcel()
x = Shell("C:\Program Files\Microsoft Office\root\Office16\EXCEL.exe", vbNormalFocus)
OpenExcel = x
End Function
Function GetOpenExcel() As excel.Application
Set GetOpenExcel = GetObject(, "Excel.Application.16")
TryAgain:
On Error GoTo NoExcel
Set xlTmp = GetObject(, "Excel.Application.16")
On Error GoTo 0
xlTmp.Visible = True
Set GetOpenExcel = xlTmp
Exit Function
NoExcel:
Resume TryAgain
End Function
And this
Set ie = Nothing
cnt = 0
cnt = xlTmp.Windows.count
sh = Shell("C:\Program Files\Microsoft Office\root\Office16\EXCEL.exe", vbNormalFocus)
Do Until xlTmp.Windows.count = cnt + 1
Loop
Set xlTmp = GetObject("excel.Application.16")
Set sh = xlTmp.Windows(xlTmp.Windows.count - 1)
I've also tried switching around my references a bit, with a little confusion, but here is what I have at the moment: MS Access References
Thanks in advance and any help would be appreciated.