PDA

Click to See Complete Forum and Search --> : MS Word VBA - Open Dialog


Travis G
Jun 11th, 2003, 03:13 PM
I want to call on the common dialog boxes so the user can select a file and I can attach to with the GetObject. I do not want the file they've selected to be opened by Word. This is what happens when I use Dialogs.Item(wdDialogFileOpen). The open dialog shows up, but when the user selects "Open", the file opens.

Any ideas?

WorkHorse
Jun 11th, 2003, 09:18 PM
.Show executes the dialog selection, .Display doesn't. The dialog will return the Name selected (not the full path name), but will set the DeafultFilePath. So to get a full file name:

' Get a document file path.
With Dialogs(wdDialogFileOpen)
.Display
strMyFileToOpen = _
Application.Options.DefaultFilePath(wdCurrentFolderPath) _
& "\" & .Name
End With
MsgBox strMyFileToOpen :)

Travis G
Jun 12th, 2003, 07:54 AM
Thanks. I was using .Show.

This code works beautifully.


Private Sub cmdImport_Click()

Dim docSelf As Document
Dim docFrom As Document
Dim varFrom As Variable

Set docSelf = ActiveDocument

With Dialogs(wdDialogFileOpen)
.Display
Set docFrom = GetObject(Application.Options.DefaultFilePath(wdCurrentFolderPath) _
& "\" & Replace(.Name, """", ""))
End With

For Each varFrom In docFrom.Variables
docSelf.Variables.Add varFrom.Name, varFrom.Value
Next

docFrom.Close wdDoNotSaveChanges

frmTemplateSave.Show
cmbTemplate.Clear
AddTemplates

End Sub


No error checking, but I'll get to that.