I want an Excel spreadsheet that has a file path and name in column A. When a macro is run, let's say the file specified in A1 should be opened on the user's machine. The file could be .doc, .xls, .txt, etc.... rather than my vba needing to know the full path the to application, how could I have the vba tell the machine "please open this file and use your application associated with the extension" ?
I have already found this to work with the full path:
dblShellReturned = Shell("C:\Windows\System32\notepad.exe myfile.txt, vbNormalFocus)
how could I get it to work with something like:
dblShellReturned = Shell("myfile.txt", vbNormalFocus) ' how do I get this to work
Thank you in advance!
The Excel VBA implementation can open files and run macros on them. In Excel, you use VBA by inserting the code in the Visual Basic Editor. You can also choose the “Macro” button on the Developer Tab.
Visual Basic for Applications runs as an internal programming language in Microsoft Office (MS Office, Office) applications such as Access, Excel, PowerPoint, Publisher, Word, and Visio.
This works for me in Excel & Word
Sub runit() Dim Shex As Object Set Shex = CreateObject("Shell.Application") tgtfile = "C:\Nax\dud.txt" Shex.Open (tgtfile) End Sub
or ... as per Expenzor's comment below
CreateObject("Shell.Application").Open("C:\Nax\dud.txt")
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With