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 Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

opening a file path in word

Status
Not open for further replies.

schltzy99

Programmer
Feb 11, 2002
33
US
How do you open a file path that is displayed in a textbox inside a word document?

So far I have the code working to click on a button that opens up a browse function. In here you select the file you want. This populates a textbox with the path to that file.

Private Sub cmdBrowse_Click()
'Dim strNewFile As String

On Error GoTo Browse_Err
With Me.cdlgOpen
'You should only use one of the next two lines if you want to open to either a default file or folder
'.FileName = EXISTINGFILE 'Comment out if you don't want to open to a default file
.InitDir = ESIXTINGDIR 'Comment out if you don't want to open to a default folder
.CancelError = True
.Filter = "Word Files (*.doc)|*.doc|"
.ShowSave
strNewFile = .FileName
End With

Browse_Exit:
Me.resume = strNewFile
Me.resume.IsHyperlink = True
Exit Sub

Browse_Err:
If Err.Number = 32755 Then
Resume Browse_Exit
Else
MsgBox Err.Number & ": " & Err.description
Resume Browse_Exit
End If
End Sub


And then I have an on click command that would open the file in the MSWord application whenever a user clicks on the textbox containing the file path

Here is what I have so far:

Private Sub resume_Click()
Dim stAppName As String
stAppName = "C:\Program Files\Microsoft Office\Office\Winword.exe "
Call Shell(stAppName, 1)
End Sub


But that only launches the program

Thanks for your help in advance![thumbsup] RSchultz
rschultz@fivestardev.com
**Access 2000**
 
have a look at faq705-1971.
Though I wrote it based on Access, the exact same code can be used in excel.

HTH

Ben ----------------------------------
Ben O'Hara
bo104@westyorkshire.police.uk
----------------------------------
 
I am a little confused on how to implement the FAQ. Do I paste that code into the on click event?

Where do I read in the file path? RSchultz
rschultz@fivestardev.com
**Access 2000**
 
Paste that code into a new module, then on the OnClick event put something like
call fHandleFile(strnewfile,WIN_Normal)
where strnewfile is variable with the name of the file you want to open.

Ben ----------------------------------
Ben O'Hara
bo104@westyorkshire.police.uk
----------------------------------
 
Thank you very much. Your insight was very helpful in getting me closer. Now I have one more quick question. Somehow, when I combine your code with my code. Following the above instructions it seems to forget to open the actual file after I close the form.

To clarify what I mean:

I click on the attact resume button, select the document I want and then click save. The documents location is now populating the text box. If I click on the documents location it will open up the document, but if I close the form and then reopen it and click on the exact same link that I clicked on before it now opens up the folder that the document is located in, but not the file.

Any ideas?

Thanks again for all of your help it is greatly appreciated. RSchultz
rschultz@fivestardev.com
**Access 2000**
 
TTT

Does anybody have any idea why this wouldn't be working right? RSchultz
rschultz@fivestardev.com
**Access 2000**
 
I'm not sure what's going on!
Are you storing the full path and filename together?
If you paste your code I will have a look at it & see what might be going wrong?
As long as you save the full filepath and name and pass them both together, then it should work. It sounds like you are only passing the file path and not the name.


Ben ----------------------------------
Ben O'Hara
bo104@westyorkshire.police.uk
----------------------------------
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top