Hello. Can someone tell me what the VB procedure would be to open a text document from a location. I have tried the Shell command. Perhaps I am doing it wrong or there is another way to do it? thanks for your help!!
~Brian
Printable View
Hello. Can someone tell me what the VB procedure would be to open a text document from a location. I have tried the Shell command. Perhaps I am doing it wrong or there is another way to do it? thanks for your help!!
~Brian
You could use:
open "c:\mydir\test.txt" for output as #1
or use the App.path object (detects where the program is being run from):
dim path as string
path = App.path + "\mydir\test.txt"
open path for output as #1
Hope this was of help!
CyberSurfer,
I tried both of those, and they didn't work. One gave me a path error (Dimming path) and the other, just plain "open" worked, but hid the document. I want it open and in focus. Can you give me any more help?
~Brian
I misinterpreted your problem. I thought you wanted to open a file for use in your program. One possible solution (This may not be any good - I'd need to know what you wanted to do with the open document) would be to copy all the lines of data into an array, and then put the array data into a multi-line text box.
This will only work with a *.txt file, a Random mode file, or a plain text file that has been given a different file extension.
You'll need to be a bit more specific about what you want the document open for though.
The 'Open For Output As' Method will work only if you want to open the text file within your program, like in a text box for example. For your problem you need ShellEx Method.
first declare this :
Private Declare Function ShellExecute Lib "shell32.dll" Alias "ShellExecuteA" (ByVal hWnd As Long, ByVal lpOperation As String, ByVal lpFile As String, ByVal lpParameters As String, ByVal lpDirectory As String, ByVal nShowCmd As Long) As Long
Then do this :
ShellExecute(0&, vbNullString, "C:\test.txt", vbNullString, vbNullString, vbNormalFocus)
In this case 'test.txt' will open in its default viewer.
You could also try this:
open an instance of Word and then open the file there.
I'm assuming you know the code for that. if not reply.
You can also open it this way as well.
The extension to Notepad is not needed, but you can add it if you want, it will work either way.Code:Shell "Notepad C:\txtfile.txt", vbNormalFocus
Code:Shell "Notepad.exe C:\txtfile.txt", vbNormalFocus
Great. Thanks so much for your help on this!! I will be clearer next time in posting as to what exactly i want to do. :(
~Brian