Results 1 to 5 of 5

Thread: Opening Word Document Without Triggering Autorun

  1. #1

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

    Opening Word Document Without Triggering Autorun

    We have a Word application that we disperse to the field. It has a VBA wizard in it, triggered by autorun. When you open the Word document, you are asked if you want to enable or disable macros. (We want to sign the document and tell the field to set us as a trusted source, but we haven't gotten that far, yet).

    The VBA code is basicly a wizard. Before the wizard, we had 10 sperate Word form documents that we sent to the field. They would have to select the correct document and fill out the correct form fields with the correct information. The wizard now prompts them, figuring out which form they need to fill out and generating it for them, with all the data filled out.

    One of the features of the wizard is templates. If you find your self filling out several of these forms for the same address, you can create a location template. Next time you need to fill out an address, select this template, and it will fill all the address fields for you.

    The template data is saved in document variables, and are unique to the copy of the document you have. Well, as we release new versions of the Word document with new versions of the VBA wizard, the users in the field have to recreate their templates.

    I had an idea, we could just open their old file, copy over all the document variables, and viola.... Using code in the newest version, I prompt them to open the old version they still have. I thought it was a good idea, but I can't avoid the Autorun trigger. So the code in the new wizard pauses as the old wizard launches.

    Any ideas? Did I just confuse everyone? Do I need to create an example?
    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
    Addicted Member
    Join Date
    Oct 2000
    Location
    Vienna/Austria
    Posts
    132
    Hi Travis, found this in google a while ago, hope this helps

    TheOnly


    To avoid Word from running autorun macro's,
    get a pointer to documents like:

    Dim d As Document
    Set d = GetObject("d:\MyDocs\Word\Testing.doc")
    d.Application.Visible = True
    d.MyMacro ArgumentOne:="Testin123"

    Using:
    Dim d As Document
    Set d = Documents.Open ... bla
    or
    Set d = Documents.Add ... bla
    will fire aurorun macro's if present

    Look at above code sequence from any other document
    but it's getting a pointer to Testing.doc.
    "Testing.doc" itself has following routines in it's
    ThisDocument module.
    Result:
    The AutoRun "Document_Open()"
    will not fire (if you use GetObject(),
    whereas the latter routine "MyMacro()" (inclduing parameter) will ...

    Private Sub Document_Open()
    MsgBox "I'm being opened"
    End Sub

    Sub MyMacro(ByVal ArgumentOne As String)
    MsgBox ArgumentOne
    End Sub

  3. #3

    Thread Starter
    Addicted Member
    Join Date
    Sep 2002
    Location
    Durham, NC, US
    Posts
    218
    This copies over the document variables, but it triggers the autorun.

    VB Code:
    1. Private Sub cmdImport_Click()
    2.  
    3.     Dim dlgOpen As Dialog
    4.     Dim docSelf As Document
    5.     Dim docFrom As Document
    6.     Dim varFrom As Variable
    7.    
    8.     Set docSelf = ActiveDocument
    9.     Set dlgOpen = Dialogs(wdDialogFileOpen)
    10.    
    11.     dlgOpen.Show
    12.    
    13.     Set docFrom = Documents.Item(Replace(dlgOpen.Name, """", ""))
    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.     cmbTemplate.Clear
    22.     AddTemplates
    23.  
    24. End Sub

    This one fails when I try to access docForm.Variables. docForm is not an object at this point, it is just a string variant set to "Bar.doc".

    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.     Set docForm = GetObject("C:\Foo\Bar.doc")
    10.     For Each varFrom In docFrom.Variables
    11.         docSelf.Variables.Add varFrom.Name, varFrom.Value
    12.     Next
    13.    
    14.     cmbTemplate.Clear
    15.     AddTemplates
    16.  
    17. End Sub
    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)

  4. #4
    Addicted Member
    Join Date
    Oct 2000
    Location
    Vienna/Austria
    Posts
    132
    Hi Travis,

    this example works fine, if you edit the typo.

    Set docForm = GetObject("C:\Foo\Bar.doc")

    should be

    set docFrom = GetObject("C:\Foo\Bar.doc")


    to avoid such typos, use "option explicit" in the module declaration.

    greetings

    TheOnly

  5. #5

    Thread Starter
    Addicted Member
    Join Date
    Sep 2002
    Location
    Durham, NC, US
    Posts
    218
    D'oh, thanks.

    I inherited this project, and I haven't cleaned everything up so I haven't set explicit. Now, it doesn't run autorun. It does ask if you want to trust the file since it has macros. I can live with 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