Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Ms Excel VBA - Using Shell command to open files

Tags:

excel

vba

I am developing a workbook in Excel-VBA and i want to execute a script using HEC DSS. That means, using excel-vba, i need to open "HEC DSS" first and then i'll instruct the application to open the script.

We keep it simple and try to correlate the above scnerio with a NotePAd.exe and a txt file. For the purpose, i have googled and tried different things but none worked. I am trying to use the SHELL command. Please find the code below:


Sub test()

Dim retval as string

dim file name as variant

filename="C:\Users\Nayar Asif\Desktop\Test_2.txt"

retval = Shell("notepad.exe" & filename, vbnormalfocus)

end sub

The above code does not work. The idea is to open the notepad application and then open the notepad file. Any help????

Regards Nayyar

like image 640
Xain Cheema Avatar asked Apr 01 '26 21:04

Xain Cheema


1 Answers

File paths with spaces should be in quotes

retval = Shell("notepad.exe """ & filename & """", vbnormalfocus)
like image 153
Tim Williams Avatar answered Apr 04 '26 11:04

Tim Williams