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

How to capture filename and path in Word?

Status
Not open for further replies.

WebCodger

Technical User
Jan 15, 2003
5
US
We have an obnoxious program on our intranet called PCDOCS. This "Big Brother" type program virtually insists that you open and close all files through its filing system. But it does not block a direct VBA command to open a file such as

WordBasic.fileopen "c:\f\wrd\adm\filename.doc" .

So my quest is to find a convenient way to pick a file, capture its name and path in a variable, then open the file, all in code, so I can store and recall files locally. As a novice, I know just enough to get a display of my files using something like

Dialogs(wdDialogFileFind).Show

but PCDOCS has clobbered the normal function of the dialog box so that a selected file won't open. Again, I need to capture the filename and path in a variable so I can use the fileopen command. Any suggestions?
 
Hi,

It can be done in Excel. I cannot find a way with the Word Object model.

So here's how...

In Word vba, reference Excel 5.0 object library or greater
Code:
'first make a reference to an Excel object library 5.0 or greater
    Dim xlApp As Excel.Application
    Set xlApp = CreateObject("Excel.Application")
    x = xlApp.GetOpenFilename("Text Files (*.txt), *.txt")
    If x <> False Then
        'stuff to do with open file
    End If
Hope this helps :)
Skip,
SkipAndMary1017@mindspring.com
 
Skip,

Appreciate your response to my question. The code you supplied did indeed bring up a dialog box to open files, however, no files can be opened using dialog boxes in my crippled version of Word, whether the dialog box comes through the Word libraries or the Excel libraries.

What I was seeking was a way to use the Word dialog box, which normally opens a file or at least displays file choices, to capture a selected file's name and path in a variable. I was hoping there was a dialog box property that would provide the name and/or path of the selected file. The filename and path could then be used in the open file command to open the selected file.

 
If &quot;no files can be opened using dialog boxes in my crippled version of Word, whether the dialog box comes through the Word libraries or the Excel libraries,&quot; then how can a Word dialog box help???

I'll have my coffee without coffee, please! :cool: Skip,
SkipAndMary1017@mindspring.com
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top