Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations biv343 on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Use VBA to Open Text File in a Seperate Program 2

Status
Not open for further replies.

bdmangum

Technical User
Dec 6, 2006
171
US
I have a macro which searches a directory to see if a text file exists. If that file exists the user is then given an option of whether they wish to veiw the file. My code runs fine, except I don't know what command to use to open the text file in an outside program such as Notepad.

Here's the code which checks for existence and then shoudl open the file.

Code:
'Checks for comments file
    MainPath = "P:\DATA\test_files"
    Set fs = CreateObject("Scripting.FileSystemObject")
    Set fold = fs.GetFolder(MainPath)
    Set f = fold.fileS

    FilePath = MainPath & "\comments.txt"
    If fs.FileExists(FilePath) = True Then
        Response = MsgBox("Comments file found.  Do you wish to view the file?", vbYesNo, "Commment File")
        
        If Response = vbYes Then
            [b]fs.OpenTextFile (FilePath)[/b]
        End If
        
    End If

I bolded the line at which I'm having trouble. I don't get an error message as it is a valid command, it just doesn't do what I need it to do. Does anyone know what command I should be using? I browsed the help files and could find anything that would do what I'm wanting to do.
 



Hi,

It should be something like
Code:
  Shell("C:\ProgramFiles\notepad.exe " & FilePath)


Skip,

[glasses] To be safe on the [red]FOURTH[/red],
Don't take a [red]FIFTH[/red] on the [red]THIRD[/red]
Or you might not come [red]FORTH[/red] on the [red]FIFTH[/red]
[red][highlight blue]FORTH[/highlight][/red][white][highlight red]WITH[/highlight][/white] [tongue]
 
What about this ?
CreateObject("WScript.Shell").Run Chr(34) & FilePath & Chr(34)

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
Thanks fellows! That solved my problem.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top