Kimchi
New Member
- Joined
- May 8, 2022
- Messages
- 3
- Office Version
- 365
- 2021
- 2019
- 2016
- Platform
- Windows
Hello,
I need to write a code that's supposed to automatically refresh a Query, then save the current workbook and close it when opening the file.
The problem is, the file also needs to be sent out. So I want to make a copy of the file that doesn't run the private sub. However, it does have other macro's it can run so I found out that saving it as .xlsx doesn't work. However, when saved as .xlsm the private sub automatically runs. Any idea's how to bypass this? Current code:
If anything needs clarification please let me know.
I need to write a code that's supposed to automatically refresh a Query, then save the current workbook and close it when opening the file.
The problem is, the file also needs to be sent out. So I want to make a copy of the file that doesn't run the private sub. However, it does have other macro's it can run so I found out that saving it as .xlsx doesn't work. However, when saved as .xlsm the private sub automatically runs. Any idea's how to bypass this? Current code:
VBA Code:
Sub Test()
Dim x As String, y As String
x = ActiveWorkbook.Path
y = Left(ActiveWorkbook.Name, Len(ActiveWorkbook.Name) - 5)
Application.DisplayAlerts = False
Application.ScreenUpdating = False
Workbooks("Quantity en revenue overview all partners Hardcopy v3 - Copy (2).xlsm").Activate
ActiveWorkbook.Connections("Query - Details").Refresh
ActiveWorkbook.SaveAs x & "" & y & "_" & Format(Date, "ddmmyyyy") & ".xlsx", FileFormat:=xlOpenXMLWorkbook
Workbooks("Quantity en revenue overview all partners Hardcopy v3 - Copy (2).xlsm").Close SaveChanges:=True
Application.ScreenUpdating = True
End Sub