简体   繁体   中英

Open txt file in notepad using extension wild card using FSO

I would like write a excel macro to open a text file in notepad with wildcard as "*.txt" using FSO Object. I need to avoid shell command as it will be blocked in my workplace.

I tried the below code but it has specific file name and also using shell command.

Sub M08_OpenTXTFiles()
Dim filename1 As String
filename1 = "C:\L2Q\L2Q-W\SOURCE\TXT\u30033.txt"
Shell ("C:\Windows\system32\notepad.exe" & " " & filename1), vbNormalFocus
End Sub

I need a macro to open a text file whose name is not known but only the extension is known as "*.txt" in a specific folder.

Any help would be appreciated. Thanks

Try this code

Sub txtopen()
ChDir "F:\Documenti" ' <<< change it
fopen = Application.GetOpenFilename("TXT files (*.txt), *.txt")
If fopen <> False Then
    Shell ("C:\Windows\system32\notepad.exe" & " " & fopen), vbNormalFocus
End If
End Sub

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