|
-
Jun 11th, 2003, 03:13 PM
#1
Thread Starter
Addicted Member
MS Word VBA - Open Dialog
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?
Travis, Kung Foo Journeyman
Web Standards: HTML 4.01, CSS Level 2, ECMA 262 Bindings to DOM Level 1, JavaScript 1.5 Guide and Reference
Perl: Documentation, Learn Perl, Llama, Camel, Cookbook, Perl Monks, Perl Mongers, O'Reilly's Perl.com, ActiveState, CPAN, TPJ, and use Perl;
OSS: Mozilla, MySQL (Manual)
-
Jun 11th, 2003, 09:18 PM
#2
Fanatic Member
.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:
VB Code:
' Get a document file path.
With Dialogs(wdDialogFileOpen)
.Display
strMyFileToOpen = _
Application.Options.DefaultFilePath(wdCurrentFolderPath) _
& "\" & .Name
End With
MsgBox strMyFileToOpen
-
Jun 12th, 2003, 07:54 AM
#3
Thread Starter
Addicted Member
Thanks. I was using .Show.
This code works beautifully.
VB Code:
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.
Travis, Kung Foo Journeyman
Web Standards: HTML 4.01, CSS Level 2, ECMA 262 Bindings to DOM Level 1, JavaScript 1.5 Guide and Reference
Perl: Documentation, Learn Perl, Llama, Camel, Cookbook, Perl Monks, Perl Mongers, O'Reilly's Perl.com, ActiveState, CPAN, TPJ, and use Perl;
OSS: Mozilla, MySQL (Manual)
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|