Hi
So I have this VBA code below which I use to export a query I have as a csv file. I am trying to get it so the query refreshes before carrying on with the export. It does the job I need, however it only refreshes after it has exported. So theoretically I have to do it twice for it to work. The 'Call ThisWorkbook.RefreshAll' I have tried in various places. I hope this makes sense. Thanks
End Sub
So I have this VBA code below which I use to export a query I have as a csv file. I am trying to get it so the query refreshes before carrying on with the export. It does the job I need, however it only refreshes after it has exported. So theoretically I have to do it twice for it to work. The 'Call ThisWorkbook.RefreshAll' I have tried in various places. I hope this makes sense. Thanks
VBA Code:
Private Sub ExportMinMaxRepricer_Click()
Dim proceed As Integer
proceed = MsgBox("Proceed With Exporting Min Max Repricer File?", vbQuestion + vbYesNo)
If proceed = vbYes Then
Dim wbkExport As Workbook
Dim shtToExport As Worksheet
Call ThisWorkbook.RefreshAll
Set shtToExport = ThisWorkbook.Worksheets("Min_Max_New") 'Sheet to export as CSV
Set wbkExport = Application.Workbooks.Add
shtToExport.Copy Before:=wbkExport.Worksheets(wbkExport.Worksheets.Count)
Application.DisplayAlerts = False 'Possibly overwrite without asking
wbkExport.SaveAs Filename:="C:\Users\xxxja\Dropbox\Repricer\Min_Max.csv", FileFormat:=xlCSV
Application.DisplayAlerts = True
wbkExport.Close SaveChanges:=False
MsgBox "Repricer Min Max Export Successful", vbInformation, "Exporting"
Else
End If
End Sub