Opening a non TXT with Notepad in excel

LS2021

New Member
Joined
Feb 17, 2021
Messages
13
Office Version
  1. 2019
Platform
  1. Windows
I have a file that i need to change that does not have a .txt but i can use notepad to open and manipulate by the open with notepad command
I have used the excel shell commend

Dim MyTxtFile
MyTxtFile = Shell("C:\WINDOWS\notepad.exe C:\TRUSTED DOCUMENTS\File Conversion\3123100 - HULU 5.wdp", 1)
and this will open the file inside of notepad that i can then use excel to change all the parts i need to do

but i don't want to hard code the location since it will change from project to project so i added this to do the file location

With Application.FileDialog(msoFileDialogFilePicker)
If .Show <> 0 Then
OrgWdpFile = .SelectedItems(1)
End If
End With
MyTxtFile = Shell("C:\WINDOWS\notepad.exe" & OrgWdpFile,1)
It finds the file but when i combine the variable i get an run time error 53

1689020240648.png

why by adding the variable not work ? it has the correct syntax that i know of?
I have tried using a copy of the wdp file as a .txt and still won't work it has something to do with using a variable?
also when i use the full text path i get some random number that make no sense and it changes each time i run the code what is this number that is not getting generated when i add the variable?

Can any one help
 

Excel Facts

Will the fill handle fill 1, 2, 3?
Yes! Type 1 in a cell. Hold down Ctrl while you drag the fill handle.
I think you just need to get the spacing right.

Try this.
VBA Code:
MyTxtFile = Shell("C:\WINDOWS\notepad.exe " & """" & OrgWdpFile & """", vbNormalFocus)
 
Upvote 0
Hi riv01
Sorry that did not work, and i also tried different amounts of ""
 
Upvote 0
I think you are going to need to provide a little more debug info than that. Try running a special test program like this one and report back on what the variable ShellString is.
VBA Code:
Sub Test()
    
    Dim ShellString As String, OrgWdpFile As String
    Dim MyTxtFile
    
    OrgWdpFile = "C:\TRUSTED DOCUMENTS\File Conversion\3123100 - HULU 5.wdp" '<- make sure this is correct
    
    ShellString = "C:\WINDOWS\notepad.exe " & """" & OrgWdpFile & """"
    Debug.Print ShellString
    
    
    With CreateObject("Scripting.FileSystemObject")
        If Not .FileExists(OrgWdpFile) Then
            MsgBox "File '" & OrgWdpFile & "' does not exist"
            Exit Sub
        End If
    End With

    MyTxtFile = Shell("C:\WINDOWS\notepad.exe " & """" & OrgWdpFile & """", vbNormalFocus)
End Sub


1689023663300.png
 
Upvote 1
Hi rlv01
Thanks for the quick response and the information as I was looking over what you had sent back a saw a difference where you had a empty space after the notepad.exe that i did not
and could not believe this could be the issue

1689078506607.png

this is my new line of code, i found it did not need the additional blank space after the ampersand or at the end, it now work
here is the current code
1689078193477.png

the one question I still have is what is the random number being generated that is in "MyTxtFile" variable? and what would it be used for? If you know can you let me know
First time run: 16512?

1689078958505.png

Second time run: 17364?
1689078140562.png


Appreciate the nudge in the right direction
Thanks for your help
 

Attachments

  • 1689078180584.png
    1689078180584.png
    3.1 KB · Views: 18
  • 1689078247142.png
    1689078247142.png
    2.5 KB · Views: 11
Upvote 0
that i did not and could not believe this could be the issue
That's why I said spacing was the issue. There must be a space between "notepad.exe" and the name of the file you are trying to open for the Shell command to work.

the one question I still have is what is the random number being generated that is in "MyTxtFile" variable?
It is not a random number. It is the Process ID (PID) of the launched program.
 
Upvote 1
Thanks again for your help and support
I will be more aware of the syntax
do I use this number To get or send information? or it is not used for anything within my script
 
Upvote 0
You don't need to use it for anything.
 
Upvote 1
Solution

Forum statistics

Threads
1,224,823
Messages
6,181,177
Members
453,021
Latest member
Justyna P

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top