简体   繁体   中英

Ms Excel VBA - Using Shell command to open files

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

带空格的文件路径应用引号引起来

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

解决方案只是notepad.exe之后和第二个引号之前的“空格”:

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM