combigning VBA Code

DrPancho

Board Regular
Joined
Jun 12, 2015
Messages
80
Hi,
Im a little stuck trying to organise the below snippits of code to work.

I want the workbook to toggle beetween worksheets at a fast rate, say 0.3sec but not sure how i should be organising the code.

Code:
Private Sub Workbook_BeforeSave(ByVal SaveAsUI As Boolean, Cancel As Boolean)
Cancel = True
MsgBox "Ah ah ah, you didn't say the magic word!", , "Your request has been denied!"
  
Workbooks("TEST.xlsm").Sheets("Trojan.exe").Select

#### REQUIRE A 0.3 SEC PAUSE #####

Workbooks("TEST.xlsm").Sheets("TrojanG.exe").Select

#### REQUIRE A 0.3 SEC PAUSE #####

Workbooks("TEST.xlsm").Sheets("Trojan.exe").Select

#### REQUIRE A 0.3 SEC PAUSE #####

Workbooks("TEST.xlsm").Sheets("TrojanG.exe").Select
Workbooks("TEST.xlsm").Sheets("Trojan.exe").Select
Workbooks("TEST.xlsm").Sheets("TrojanG.exe").Select
Workbooks("TEST.xlsm").Sheets("Trojan.exe").Select
Workbooks("TEST.xlsm").Sheets("TrojanG.exe").Select
End Sub

At the top i have the following code....
Code:
#If VBA7 Then ' Excel 2010 or later
Private Declare PtrSafe Sub Sleep Lib "kernel32" (ByVal Milliseconds As LongPtr)
#Else ' Excel 2007 or earlier
Private Declare Sub Sleep Lib "kernel32" (ByVal Milliseconds As Long)
#End If

.... Now this is where im stuck, I know i need to create a loop then call the loop in beetween the change of worksheets but my online copy & paste skills are running low lol

Any suggestions or advice would be appriciated
Thanks
Pancho!
 

Excel Facts

Copy a format multiple times
Select a formatted range. Double-click the Format Painter (left side of Home tab). You can paste formatting multiple times. Esc to stop

Forum statistics

Threads
1,214,897
Messages
6,122,148
Members
449,066
Latest member
Andyg666

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