MEUserII
Board Regular
- Joined
- Oct 27, 2017
- Messages
- 91
- Office Version
- 365
- 2021
- 2019
- 2016
- 2013
- Platform
- Windows
I have a macro which uses Shell to open a TXT file in Notepad. I am trying to get this macro to work with opening a TXT file in Notepad beginning with the first part of the filename; I have listed below my two attempts to have this work (MacroAttempt1 and MacroAttempt2):
Sub MacroAttempt1()
Dim filename1 As String
filename1 = "C:\Users\FLast\Desktop\Folder\1234 (ABCD-EFGH) (IJ) (03-21-2018__0000-00) (TXT).TXT"
Shell ("C:\Windows\system32\notepad.exe" & " " & filename1), vbNormalFocus
End Sub
Sub MacroAttempt2()
Dim filename2 As String
filename2 = "C:\Users\FLast\Desktop\Folder" & "1234" & "*(TXT).TXT"
Shell ("C:\Windows\system32\notepad.exe" & " " & filename2), vbNormalFocus
End Sub
The first macro, MacroAttempt1, works successfully. However, the second macro, MacroAttempt2, which is supposed to open the TXT file beginning with the first part of the filename "1234" and an asterisk ("*") and ends with "(TXT).TXT" does not work.
How would I fix this macro, so that it opens the TXT file beginning with the first part of the filename?
Sub MacroAttempt1()
Dim filename1 As String
filename1 = "C:\Users\FLast\Desktop\Folder\1234 (ABCD-EFGH) (IJ) (03-21-2018__0000-00) (TXT).TXT"
Shell ("C:\Windows\system32\notepad.exe" & " " & filename1), vbNormalFocus
End Sub
Sub MacroAttempt2()
Dim filename2 As String
filename2 = "C:\Users\FLast\Desktop\Folder" & "1234" & "*(TXT).TXT"
Shell ("C:\Windows\system32\notepad.exe" & " " & filename2), vbNormalFocus
End Sub
The first macro, MacroAttempt1, works successfully. However, the second macro, MacroAttempt2, which is supposed to open the TXT file beginning with the first part of the filename "1234" and an asterisk ("*") and ends with "(TXT).TXT" does not work.
How would I fix this macro, so that it opens the TXT file beginning with the first part of the filename?
Last edited: