Results 1 to 3 of 3

Thread: MS Word VBA - Open Dialog

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Sep 2002
    Location
    Durham, NC, US
    Posts
    218

    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)

  2. #2
    Fanatic Member WorkHorse's Avatar
    Join Date
    Jul 2002
    Location
    Where you live.
    Posts
    591
    .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:
    1. ' Get a document file path.
    2. With Dialogs(wdDialogFileOpen)
    3.     .Display
    4.     strMyFileToOpen = _
    5.         Application.Options.DefaultFilePath(wdCurrentFolderPath) _
    6.         & "\" & .Name
    7. End With
    8. MsgBox strMyFileToOpen

  3. #3

    Thread Starter
    Addicted Member
    Join Date
    Sep 2002
    Location
    Durham, NC, US
    Posts
    218
    Thanks. I was using .Show.

    This code works beautifully.

    VB Code:
    1. Private Sub cmdImport_Click()
    2.  
    3.     Dim docSelf As Document
    4.     Dim docFrom As Document
    5.     Dim varFrom As Variable
    6.    
    7.     Set docSelf = ActiveDocument
    8.    
    9.     With Dialogs(wdDialogFileOpen)
    10.         .Display
    11.         Set docFrom = GetObject(Application.Options.DefaultFilePath(wdCurrentFolderPath) _
    12.                                 & "\" & Replace(.Name, """", ""))
    13.     End With
    14.    
    15.     For Each varFrom In docFrom.Variables
    16.         docSelf.Variables.Add varFrom.Name, varFrom.Value
    17.     Next
    18.    
    19.     docFrom.Close wdDoNotSaveChanges
    20.    
    21.     frmTemplateSave.Show
    22.     cmbTemplate.Clear
    23.     AddTemplates
    24.  
    25. 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
  •  



Click Here to Expand Forum to Full Width