VB Script Wait

davidpayten

Board Regular
Joined
May 24, 2004
Messages
225
Hi All,

Again, thanks for ppl giving me solutions to all the problems I have had so far in the past, this forum has been a godsend.

I have a issue where My vb script executes a .bat file and then outputs a zip file. The problem is is that I need to tell the script to stop while the bat file is running so it can run the rest of the code:

esentially the process,

1) gets a file from a dirctory and drops in a mydirectory
2) it then unzips the file via a bat
3) it then renames the unzipped file into a generic name

ATM I have a seperate 1,2 from 3 for it to work, here is my code so far, at line 36 i have inserted "Wscript.Sleep 1500" but it doesn't appear to stop vb script while it executes a vb script so it can succefully execute 3) above.

Thanks People here is my code so far:





Dim fs, f, f1, fc, s,d

'gets zip bat file - if you change where .bat file is change it here'

Set WshShell = WScript.CreateObject("WScript.Shell")
'WshShell.Run "D:\Scripts\iprevenue scripts\unzipfile.bat"

' gets the postbill file'

Set fs = CreateObject("Scripting.FileSystemObject")
DestinationFolder = "J:\Upload Data\connect\"
folderspec = "G:\BTS\Tech Delivery\general\Development\Business Systems\Mifs\DatabaseWork\mifs_cca_revenue\"
Set f = fs.GetFolder(folderspec)
Set fc = f.Files
For Each f1 in fc
If Left(f1.name,11) = "postbillcca" Then
s = left(datevalue(f1.datecreated),10)
If s = left(datevalue(Now()),10) Then
fs.GetFile(f1).copy DestinationFolder
Filename = DestinationFolder & f1.Name
NewFileName = DestinationFolder & "postbillcca.zip"
fs.MoveFile Filename, NewFileName

End if

End if
Next
MsgBox s

'calls zip bat file and extracts the zip file to same directory as where zip file resides'
'will need to change unzip file to the server directory'

WshShell.Run "D:\Scripts\iprevenueScripts\unzipfile.bat"
'script.WshShell.Wait [1500]'
Wscript.Sleep 1500

'Rename unziped file to generic file so access can pickup file'


folderspec = "J:\Upload Data\connect\"
Set f = fs.GetFolder(folderspec)
Set fc = f.Files
For Each f1 in fc
If Instr(1,f1.name,"postbillcca") > 0 AND right(f1.name,3) = "txt" Then

fs.GetFile(f1).copy folderspec
Filename = folderspec & f1.Name
NewFileName = folderspec & "postbillcca.txt"
fs.MoveFile Filename, NewFileName

End if


Next
 

Excel Facts

Waterfall charts in Excel?
Office 365 customers have access to Waterfall charts since late 2016. They were added to Excel 2019.
To make the macro wait for something else to process, you could try:
Code:
Application.Wait TimeSerial(Hour(Now()), Minute(Now()), Second(Now()) + 10)
This would create a 10 second pause in the macro.
 
Upvote 0

Forum statistics

Threads
1,214,954
Messages
6,122,462
Members
449,085
Latest member
ExcelError

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