VBA to turn off web query connection

gvillepa

New Member
Joined
Oct 18, 2017
Messages
36
HI,

This runs a macro every 5 minutes in order to .SaveCopyAs.

The master file conducts a power query from web every 1 minute. I .SaveCopyAs to another file name/location every 5 minutes. Obviously, it saves an actual copy of the master file, including the webconnection (which is set to run on open for the master file - and it needs to stay that way)

Basically, I want the cloned copy to not have the web query connection and I'm hoping there is a way to disable the web query connection on the master file, then savecopyas, then re-enable web query connection so the master file can resume making clones every 5 minutes and refreshing every 1 minute.

Any thoughts or better approaches?



Code:
Public dTime As DateSub Workbook_Open()
    dTime = Now + TimeValue("00:00:05")
    Application.OnTime dTime, "MyMacro"
End Sub
Sub Workbook_BeforeClose(Cancel As Boolean)
   Application.OnTime dTime, "MyMacro", , False
End Sub


Sub MyMacro()
    dTime = Now + TimeValue("00:02:00")
    Application.OnTime dTime, "MyMacro"
     
    ActiveWorkbook.SaveCopyAs ("C:\Users\TheNameOfUser\Desktop\Currency\" & Format(Now(), "yyyy-mmdd-hhmm") & ".xlsm")
     


End Sub
 
Last edited:

Excel Facts

Show numbers in thousands?
Use a custom number format of #,##0,K. Each comma after the final 0 will divide the displayed number by another thousand

Forum statistics

Threads
1,223,903
Messages
6,175,284
Members
452,630
Latest member
OdubiYouth

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top