PDA

View Full Version : Solved: Get Document name



mdmackillop
08-20-2006, 04:00 PM
I need to get a Word document name from a dialog box to open from Excel, but my mind's gone blank. :banghead:
Something like
ChDir ActiveWorkbook.Path
fName = Application.FindFile
Set wdDoc = wdApp.Documents.Open(fName)

Bob Phillips
08-20-2006, 04:09 PM
I need to get a Word document name from a dialog box to open from Excel, but my mind's gone blank. :banghead:
Something like
ChDir ActiveWorkbook.Path
fName = Application.FindFile
Set wdDoc = wdApp.Documents.Open(fName)


Don't you need to create an insatnce of Word, and open it from within there?

mdmackillop
08-20-2006, 04:40 PM
Here's my code. It's opening the file in Word, rather than just returning the file name. I was sure there was a dialog for that, similar to browsing for a folder name.


Sub DataFrom()

'Remember: this code requires a referece to the Word object model

Dim wdApp As New Word.Application
Dim wdDoc As Word.Document
Dim fName As String
Dim i As Long
Dim f

ChDir ActiveWorkbook.Path
'maybe
fName = wdApp.Dialogs(wdDialogFileFind).Show
'or
fName = wdApp.Dialogs(wdDialogFileOpen).Show

Set wdDoc = wdApp.Documents.Open(fName)


For Each f In wdDoc.FormFields
i = i + 1
On Error Resume Next
Cells(i, 1) = f.Result
Next
End Sub

mdmackillop
08-20-2006, 05:15 PM
Found it.

With Application.FileDialog(msoFileDialogOpen)
.AllowMultiSelect = True
.Show
' Display paths of each file selected
For lngCount = 1 To .SelectedItems.Count
MsgBox .SelectedItems(lngCount)
Next lngCount
End With