NeroMaj
08-26-2010, 05:58 AM
I am writing a Macro in Word VBA that will open another word file, read some data from a specific table in that file (I know Excel is easier for readign tables, but not possible for my particular goals), and then calculate some values.
The only problem I am having is referencing the newly opened file once it is opened.
I have the following setup:
*****************************************************
Dim wdApp as Word.Application
Dim wdDoc as Word.Document
Sub OpenSingleFile()
Dialogs(wdDialogFileOpen).Show
End Sub
I know how to set the different properties of a dialog box and all of that, but how can I return the file path name...e.g. If file was "Compliance Evaluation" I would want to return "c:\My Documents\Compliance Evaluation.doc"
**************************************************
*What code here can return the path name of the file or is it even
*possible? As you can see I want to get the file path and then
*use that to open the document as part of wdApp collection so
*that I can use With wdApp to navigate through the document
**************************************************
Sub OpenSingleFile()
Dim FileName as string
'Dialogs(wdDialogFileOpen).Show
FileName = ??????????????????
On Error Resume Next
Set wdApp = CreateObject("Word.Application")
If Err.Number<> 0 Then
Set wdApp = CreateObject("Word.Application")
End If
On Error GoTo 0
wdDoc = wdApp.Documents.?????????????????
End Sub
The only problem I am having is referencing the newly opened file once it is opened.
I have the following setup:
*****************************************************
Dim wdApp as Word.Application
Dim wdDoc as Word.Document
Sub OpenSingleFile()
Dialogs(wdDialogFileOpen).Show
End Sub
I know how to set the different properties of a dialog box and all of that, but how can I return the file path name...e.g. If file was "Compliance Evaluation" I would want to return "c:\My Documents\Compliance Evaluation.doc"
**************************************************
*What code here can return the path name of the file or is it even
*possible? As you can see I want to get the file path and then
*use that to open the document as part of wdApp collection so
*that I can use With wdApp to navigate through the document
**************************************************
Sub OpenSingleFile()
Dim FileName as string
'Dialogs(wdDialogFileOpen).Show
FileName = ??????????????????
On Error Resume Next
Set wdApp = CreateObject("Word.Application")
If Err.Number<> 0 Then
Set wdApp = CreateObject("Word.Application")
End If
On Error GoTo 0
wdDoc = wdApp.Documents.?????????????????
End Sub