Hi,
I am having problems with Access opening an excel file and running a macro, it seems to open excel in a non visible format but I have no idea why?, I am sure I am missing something simple, and would appreciate it if some one could point me in the right direction.
Thanks
Josh
This is the code I am using in access: -
Private Sub updatecompetitorsladderssummary_Click()
Dim stDocName As String
Dim ExcelLocation As String
Dim ExcelName As String
Dim xlapp As Excel.Application
Dim xlbook As Excel.Workbook
'Change these 2 if the Comp Ladder Summary spreadsheet is moved
ExcelLocation = "M:\Pricing\Products and Pricing\Archive Pricing Papers\"
ExcelName = "Comp Ladder Summary.xls"
'This runs the relevant create table and append queries
DoCmd.SetWarnings False
DoCmd.OpenQuery "Query 4002 Grouped Data for Summary Comp Ladders", acViewNormal, acEdit
DoCmd.SetWarnings True
'Checks if excel is open, and names the current instance as xlapp, if not opens it and names it xlapp
On Error Resume Next
Set xlapp = GetObject(, "Excel.Application")
If Err Then
Set xlapp = New Excel.Application
End If
xlapp.Visible = True
Workbooks.Open Filename:=(ExcelLocation & ExcelName), UpdateLinks:=1
Set xlbook = ActiveWorkbook
xlapp.Application.Run "UpdateGraphs"
End Sub
I am having problems with Access opening an excel file and running a macro, it seems to open excel in a non visible format but I have no idea why?, I am sure I am missing something simple, and would appreciate it if some one could point me in the right direction.
Thanks
Josh
This is the code I am using in access: -
Private Sub updatecompetitorsladderssummary_Click()
Dim stDocName As String
Dim ExcelLocation As String
Dim ExcelName As String
Dim xlapp As Excel.Application
Dim xlbook As Excel.Workbook
'Change these 2 if the Comp Ladder Summary spreadsheet is moved
ExcelLocation = "M:\Pricing\Products and Pricing\Archive Pricing Papers\"
ExcelName = "Comp Ladder Summary.xls"
'This runs the relevant create table and append queries
DoCmd.SetWarnings False
DoCmd.OpenQuery "Query 4002 Grouped Data for Summary Comp Ladders", acViewNormal, acEdit
DoCmd.SetWarnings True
'Checks if excel is open, and names the current instance as xlapp, if not opens it and names it xlapp
On Error Resume Next
Set xlapp = GetObject(, "Excel.Application")
If Err Then
Set xlapp = New Excel.Application
End If
xlapp.Visible = True
Workbooks.Open Filename:=(ExcelLocation & ExcelName), UpdateLinks:=1
Set xlbook = ActiveWorkbook
xlapp.Application.Run "UpdateGraphs"
End Sub