0

I have been working on several user-forms and have a command to write the resulting string to a text file. However the issue I run into is one where I have a hardcoded shell command that I need to work on any computer.

myFile = "C:\Reformatted.txt"
Open myFile For Output As #1

Print #1, UserEntry 'Write string to the file.
Close #1

Shell "C:\Windows\Notepad.exe C:\Reformatted.txt", 1 'Opens up the text file.

The issue here as you can see is that while every computer (all windows) will have notepad, they wont be in the same filepath. In addition different computers and users will want to save it in different folders.

I want to use this:

Application.GetSaveAsFilename

How can I make it to write to the txt file?

Any tips?

Community
  • 1
  • 1
Dasman
  • 317
  • 4
  • 19
  • Maybe take a look here: http://stackoverflow.com/questions/18921168/how-can-excel-vba-open-file-using-default-application You can shell the file itself, and allow it to open in its "default" application. – Tim Williams Jul 17 '15 at 20:51

1 Answers1

0
Sub Tester()

    Dim myFile

    myFile = "C:\_Stuff\temp.txt"

    Open myFile For Output As #1
    Print #1, "Hello" 'Write string to the file.
    Close #1

    CreateObject("Shell.Application").Open myFile

End Sub
Tim Williams
  • 154,628
  • 8
  • 97
  • 125