Hi,
I am completely new to VBA and to be honest I don't really know what I am doing. I've pieced the below code together but It doesn't run when the workbook is opened, and if I start it manually it saves and closes before the query refresh is completed. Where am I going wrong? Aim is to open the excel file using a batch file and windows task scheduler, refresh the query, save the file and close.
I am completely new to VBA and to be honest I don't really know what I am doing. I've pieced the below code together but It doesn't run when the workbook is opened, and if I start it manually it saves and closes before the query refresh is completed. Where am I going wrong? Aim is to open the excel file using a batch file and windows task scheduler, refresh the query, save the file and close.
VBA Code:
Sub Workbook_Open()
Call RefreshQuery
ActiveWorkbook.Save
If Application.Workbooks.Count = 1 Then
Application.Quit
Else
ActiveWorkbook.Close
End If
End Sub
Sub RefreshQuery()
'
' RefreshQuery Macro
'
'
ActiveWorkbook.Connections("Query").Refresh
End Sub