![]() ![]() Step 2 – Exploration is a cinch in this case too and is covered from lines 14-17. Essentially, this all happens on lines 11-12, where we assign a reference to Sheet1 and store it in the wks variable… easy cheesy. Sweet! Let’s review how it works with our trusty 4-step VBA process: Run batch file, wait on results, modify the results Sound good? Good - here’s the code in action: Then, we need to rename the new folder that results from that batch file using some info from cells D3 and E3 on Sheet1. Let’s say that first, we need to run the batch file. Prepend your strCommand variable with cmd /K.What if you want to use the some of the old CMD standby commands, like MOVE or REN? In that case, you need to: WaitOnReturn takes True or False - if you want VBA to, you know, WAIT until the command finishes, set it to True! If you want the operation to happen invisibly, set WindowStyle to 0 - if you actually want to see CMD come up and execute the command, though, you can set WindowStyle:=1 instead. ( 0 is the ideal output from WshShell.Run.) Line 11-13: the WshShell.Run command returns a number, so we set it a variable we can later check for errors. "C:\wshshell-fun\Create New 2015 Project Folder.bat" We will need these because the full path to our batch file includes spaces, so variable strCommand becomes: Line 10: we use Chr(34) to indicate a double quote character, ". Nice! Here’s a quick run-down of the juicy bits: Here’s a link to the code above so you can review it side-by-side with the walk through below. The following code will run that file and wait for the batch file to finish before moving on. ![]() Suppose our batch file is named “Create New 2015 Project Folder.bat” and it’s sitting in C:\wshshell-fun. Make sure the Windows Script Host Object Model is selectedĬool! You know have access to the WshShell object, which will let you WshShell.Run batch files or even regular old CMD commands. ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |