Open a file from VBA

anichols

Board Regular
Joined
Mar 11, 2021
Messages
87
Office Version
  1. 365
Platform
  1. Windows
Hello all,

I found this online, and I think it is very close to what I am trying to do, but haven't had much luck in adjusting it to my needs. I am just looking for a way for VBA to open a file. In this case a .PS1 file.
VBA Code:
Sub RunAndGetCmd()

    strCommand = "Powershell -File ""C:\Users\drew\Desktop\showDSKTP.ps1"""
    Set WshShell = CreateObject("WScript.Shell")
    Set WshShellExec = WshShell.Exec(strCommand)
    strOutput = WshShellExec.StdOut.ReadAll
    'MsgBox strOutput

End Sub
Any help would be greatly appreciated.
 

Excel Facts

Move date out one month or year
Use =EDATE(A2,1) for one month later. Use EDATE(A2,12) for one year later.
See if this works ...

Sub test()
'Call Powershell and run scripts
Call Shell("powershell -noexit -file ""C:\Users\drew\Desktop\showDSKTP.ps1", vbMaximizedFocus)
End Sub


Calling a PS script from VBA
 
Upvote 0
Does this work ?
VBA Code:
ActiveWorkbook.FollowHyperlink "C:\Users\drew\Desktop\showDSKTP.ps1"
 
Upvote 0

Forum statistics

Threads
1,224,824
Messages
6,181,186
Members
453,020
Latest member
Mohamed Magdi Tawfiq Emam

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