Dale Logan
asked on
Run script from within Excel
Experts,
I received a solution to the following question that works perfectly. However, to get the results, a script must be run from a command prompt. Is there anyway to have this done from within Excel?
Previously asked question: Solution
Command lines to run script:
cd /d C:\Scripts\GetHandicap
powershell.exe -ExecutionPolicy Unrestricted -File GetHandicap.ps1
Thanks, Dale
I received a solution to the following question that works perfectly. However, to get the results, a script must be run from a command prompt. Is there anyway to have this done from within Excel?
Previously asked question: Solution
Command lines to run script:
cd /d C:\Scripts\GetHandicap
powershell.exe -ExecutionPolicy Unrestricted -File GetHandicap.ps1
Thanks, Dale
ASKER
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
zalazar,
Just so you know, this runs correctly. However, there is no way to know when the process has finished. The Command window stays open. Only when I close it, does the data populate in Excel. So, I just have to wait long enough before closing the window. Is there anyway for the process to know it has finished and then have it close the Command window?
Just so you know, this runs correctly. However, there is no way to know when the process has finished. The Command window stays open. Only when I close it, does the data populate in Excel. So, I just have to wait long enough before closing the window. Is there anyway for the process to know it has finished and then have it close the Command window?
That's indeed not so easy then. I actually do not have the problem myself.
While looking at it, things could probably be done better and therefore I have written some Excel VBA code that does the same as the PowerShell script.
You can also specify the users in the Excel sheet now instead of a txt file.
I have attached an Excel workbook that you can use.
Within the workbook you have to fill in the correct parameters in column B.
From the script directory curl.exe is used.
The users column, start and end row have to be defined.
It's not a problem if you put in a higher number for "Users Row End" as empty cells are automatically skipped.
Hopefully this works without any problem and hopefully it also makes the process easier.
GetHandicap-v10.xlsb
While looking at it, things could probably be done better and therefore I have written some Excel VBA code that does the same as the PowerShell script.
You can also specify the users in the Excel sheet now instead of a txt file.
I have attached an Excel workbook that you can use.
Within the workbook you have to fill in the correct parameters in column B.
From the script directory curl.exe is used.
The users column, start and end row have to be defined.
It's not a problem if you put in a higher number for "Users Row End" as empty cells are automatically skipped.
Hopefully this works without any problem and hopefully it also makes the process easier.
GetHandicap-v10.xlsb
ASKER
zalazar,
This is awesome. Thank you so much.
Dale
This is awesome. Thank you so much.
Dale
You're most welcome.
Try this
Private Sub CommandButton1_Click()
Dim strProgramName As String
Dim strArgument As String
strProgramName = "C:\Scripts\GetHandicap\po
strArgument = " -ExecutionPolicy Unrestricted -File GetHandicap.ps1"
Call Shell("""" & strProgramName & """ """ & strArgument & """", vbNormalFocus)
End Sub
To-run-from-excel.xlsm