When the button is clicked, I want the file to be opened.
The file will be in the same directory as the visual basic project.
Therefore, I need the code to open the file using "app.Path".
Any solutions?
Printable View
When the button is clicked, I want the file to be opened.
The file will be in the same directory as the visual basic project.
Therefore, I need the code to open the file using "app.Path".
Any solutions?
Dim intFile As Integer
intFile = FreeFile
Open App.Path + "\myTextFile.txt" For Input As intFile
strData = Input(LOF(intFile), intFile)
Close intFile
OR
selfile = App.Path + "\myTextFile.txt"
Open selfile For Input As #1 ' Open file for input.
Do While Not EOF(1) ' Check for end of file.
Line Input #1, myLine1 ' Read line of data.
myWholeLine = myWholeLine & myLine1
Loop
Close #1
You really should use & rather than + when combining strings
Code:Open App.Path & "\myTextFile.txt" For Input As intFile
No no guyz.... I literally want the file to be opened in windows when I click the button.
@DM--I know....bad old habit.....thx for the reminder.....
@Skate...use the Shell command
Like:
Shell app.path & "\yourFileName.exe", vbNormalFocus
You are not OPENING a file then, you are RUNNING (or executing) one.
If you NOT running an executable file (.exe, bat, etc), but want to open, say, a Word Document (.doc, .docx, etc), you would NOT use my example. Please be a bit more explicit on what you are actually trying to do...what kind of file do you want to 'open' (sic)
I saw your other thread...why didn't you just answer my question in the previous post...
Here is how you can do it...
Shell "c:\windows\system32\xpsrchvw.exe " & App.Path & "\yourfilename.xps"
I am using Win7...xpsrchvw.exe is found in the system32
On XP OSs, you can use xpsviewer.exe instead (also found in system32 directory)
use shellexecute api, will open in the default program for file type, assuming there is one, not all XP machines have an installed application for opening .xps
i use freeopener to open .xps, as the microsoft .xps reader failed to install correctly
many examples of shellexecute in this forum