I need to get a Word document name from a dialog box to open from Excel, but my mind's gone blank.
Something like
[VBA]ChDir ActiveWorkbook.Path
fName = Application.FindFile
Set wdDoc = wdApp.Documents.Open(fName)
[/VBA]
I need to get a Word document name from a dialog box to open from Excel, but my mind's gone blank.
Something like
[VBA]ChDir ActiveWorkbook.Path
fName = Application.FindFile
Set wdDoc = wdApp.Documents.Open(fName)
[/VBA]
MVP (Excel 2008-2010)
Post a workbook with sample data and layout if you want a quicker solution.
To help indent your macros try Smart Indent
Please remember to mark threads 'Solved'
Don't you need to create an insatnce of Word, and open it from within there?Originally Posted by mdmackillop
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.
[vba]
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
[/vba]
MVP (Excel 2008-2010)
Post a workbook with sample data and layout if you want a quicker solution.
To help indent your macros try Smart Indent
Please remember to mark threads 'Solved'
Found it.
[VBA]
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
[/VBA]
MVP (Excel 2008-2010)
Post a workbook with sample data and layout if you want a quicker solution.
To help indent your macros try Smart Indent
Please remember to mark threads 'Solved'