hi
i have 2 separate queries one to referesh
the other to export
as many times as as i try to combine them somehow i strip the queries form the main book and it breaks
separately they both work fine it doesnt matter which i run first or second
please help me combine and call the refresh from the export module
i fail the books again and again
refresh module
Sub RefreshPQs()
Dim ws As Worksheet
Dim ActSheet As String: ActSheet = ActiveSheet.Name
If MsgBox("Did you update Timeclock Download Folder (Yellow Cell)?", vbYesNo + vbCritical) = vbNo Then
MsgBox "Please choose Viventium Upload Folder to Update"
Exit Sub
End If
ThisWorkbook.Activate
Set wb = ThisWorkbook
'Unprotect
For Each ws In wb.Worksheets
Call WSUnProtect(ws)
Next ws
'Refresh All
wb.RefreshAll
DoEvents
' Call ExportCopy
'Protect
For Each ws In wb.Worksheets
Call WSProtect(ws)
Next ws
Worksheets(ActSheet).Activate
' Call SendEmail
MsgBox "Process Complete", vbInformation
End Sub
i have 2 separate queries one to referesh
the other to export
as many times as as i try to combine them somehow i strip the queries form the main book and it breaks
separately they both work fine it doesnt matter which i run first or second
please help me combine and call the refresh from the export module
i fail the books again and again
Rich (BB code):
Sub ExportCopy()
Dim SaveFolder1 As String: SaveFolder1 = "M:\all\Exports Copied Sheets\"
Dim FileName As String
Dim FileDateTime As String: FileDateTime = Format(Now, "m-d-yy hh-mm")
Dim FullFileName As String
Dim ReportDoc As String: ReportDoc = Worksheets("Variables").Range("ReportDocument")
Dim cn As WorkbookConnection
Dim qry As WorkbookQuery
Dim NewWB As Workbook
FileName = "Copies " & ReportDoc
FullFileName = Replace(FileName, ".xlsx", "") & " (" & FileDateTime & ")"
Sheets(Array(" bef 12", " 6am", " before 6 AM", "12am", "Hours", "ALL times")).Copy
Set NewWB = ActiveWorkbook
'Clean PQ
NewWB.Activate
On Error Resume Next
For Each cn In NewWB.Connections
cn.Delete
Next cn
For Each qry In NewWB.Queries
qry.Delete
Next qry
'Save and Close New WB
NewWB.SaveAs SaveFolder1 & FullFileName & ".xlsx", xlOpenXMLWorkbook
NewWB.Close SaveChanges:=False
DoEvents
'Back to Main WB
ThisWorkbook.Activate
'MsgBox "Process Complete"
End Sub
Sub RefreshPQs()
Dim ws As Worksheet
Dim ActSheet As String: ActSheet = ActiveSheet.Name
If MsgBox("Did you update Timeclock Download Folder (Yellow Cell)?", vbYesNo + vbCritical) = vbNo Then
MsgBox "Please choose Viventium Upload Folder to Update"
Exit Sub
End If
ThisWorkbook.Activate
Set wb = ThisWorkbook
'Unprotect
For Each ws In wb.Worksheets
Call WSUnProtect(ws)
Next ws
'Refresh All
wb.RefreshAll
DoEvents
' Call ExportCopy
'Protect
For Each ws In wb.Worksheets
Call WSProtect(ws)
Next ws
Worksheets(ActSheet).Activate
' Call SendEmail
MsgBox "Process Complete", vbInformation
End Sub
Rich (BB code):
Sub RefreshPQs()
Dim ws As Worksheet
Dim ActSheet As String: ActSheet = ActiveSheet.Name
If MsgBox("Did you update Timeclock Download Folder (Yellow Cell)?", vbYesNo + vbCritical) = vbNo Then
MsgBox "Please choose Viventium Upload Folder to Update"
Exit Sub
End If
ThisWorkbook.Activate
Set wb = ThisWorkbook
'Unprotect
For Each ws In wb.Worksheets
Call WSUnProtect(ws)
Next ws
'Refresh All
wb.RefreshAll
DoEvents
' Call ExportCopy
'Protect
For Each ws In wb.Worksheets
Call WSProtect(ws)
Next ws
Worksheets(ActSheet).Activate
' Call SendEmail
MsgBox "Process Complete", vbInformation
End Sub
Sub RefreshPQs_Folders()
Dim ws As Worksheet
Dim wb As Workbook
Dim ActSheet As String: ActSheet = ActiveSheet.Name
If wb Is Nothing Then
Set wb = ThisWorkbook
End If
' 'Unprotect
For Each ws In wb.Worksheets
Call WSUnProtect(ws)
Next ws
wb.Connections("Query - ALL timeclock downloads 2023").Refresh
' 'Protect
For Each ws In wb.Worksheets
Call WSProtect(ws)
Next ws
Worksheets(ActSheet).Activate
MsgBox "It is now possible to choose the folder path", vbInformation
End Sub