|
-
Jun 6th, 2003, 09:14 AM
#1
Thread Starter
Addicted Member
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)
-
Jun 9th, 2003, 11:55 AM
#2
Addicted Member
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
-
Jun 10th, 2003, 10:21 AM
#3
Thread Starter
Addicted Member
This copies over the document variables, but it triggers the autorun.
VB Code:
Private Sub cmdImport_Click()
Dim dlgOpen As Dialog
Dim docSelf As Document
Dim docFrom As Document
Dim varFrom As Variable
Set docSelf = ActiveDocument
Set dlgOpen = Dialogs(wdDialogFileOpen)
dlgOpen.Show
Set docFrom = Documents.Item(Replace(dlgOpen.Name, """", ""))
For Each varFrom In docFrom.Variables
docSelf.Variables.Add varFrom.Name, varFrom.Value
Next
docFrom.Close wdDoNotSaveChanges
cmbTemplate.Clear
AddTemplates
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:
Private Sub cmdImport_Click()
Dim docSelf As Document
Dim docFrom As Document
Dim varFrom As Variable
Set docSelf = ActiveDocument
Set docForm = GetObject("C:\Foo\Bar.doc")
For Each varFrom In docFrom.Variables
docSelf.Variables.Add varFrom.Name, varFrom.Value
Next
cmbTemplate.Clear
AddTemplates
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)
-
Jun 10th, 2003, 02:25 PM
#4
Addicted Member
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
-
Jun 11th, 2003, 12:56 PM
#5
Thread Starter
Addicted Member
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|