Writing to correct document

  • Thread starter Stephen English
  • Start date
S

Stephen English

Hi
I have 30 templates which, when they open (call the instance docA), load a
master template which stores user forms and code applicable to all 30
templates. I am not and do not wish to put this master template in any Word
startup folder because it is with the 30 master templates in a folder to make
it transportable to offline computers.

After I load the master template, I load the user form which is stored on
the master template. When I click OK on the user form and update bookmarks,
it trying to find the bookmarks on the Master template whereas I want it to
locate and update them on docA.

Please can anyone tell me how to keep track of this document without saving
it somewhere and reopening it. docActive in code below is not working.
Thanks
Stephen

Public Sub AutoNew()
Dim strPath As String
Dim obj As Object
Dim docActive As Document

strPath = ActiveDocument.AttachedTemplate.Path & "\"
' Open master template
Set obj = Documents.Open(strPath & "ProjectManagement.dot")
Set docActive = ActiveDocument

Application.Run "FillProjectCombo"
Application.Run "FillNameCombo"
Application.Run "ShowForm1", docActive

End Sub
 
R

Russ

Where's your code for DocA?
like:
Dim DocA As Document
Set DocA = Activedocument
Before you open the template it is based on.

Then you can always refer to DocA and *its* bookmarks.

Did you read all the limitations on the run command in VBA help?
Does your implementation exceed those limits?
Runs a Visual Basic macro.
Note Only public Sub procedures that take no arguments, which includes all
procedures generated by the macro recorder and all procedures you can run
from the Macros dialog box, can be run by using the Run method.
Syntax
expression.Run(MacroName)
expression Required. An expression that returns an Application object.
MacroName Required String. The name of the macro. Can be any combination
of template, module, and macro name. For example, the following statements
are all valid.
Application.Run "Normal.Module1.MAIN"
Application.Run "MyProject.MyModule.MyProcedure"
Application.Run "'My Document.doc'!ThisModule.ThisProcedure"
If you specify the document name, your code can only run macros in documents
related to the current context, not just any macro in any document.
Remarks
Although Visual Basic code can call a macro directly (without this method
being used), this method is useful when the macro name is stored in a
variable (for more information, see the example for this topic). The
following statements are functionally equivalent.
Normal.Module2.Macro1
Call Normal.Module2.Macro1
Application.Run MacroName:="Normal.Module2.Macro1"
You cannot pass parameters to a procedure by using the Run method. Use the
Call statement to pass parameters to a procedure.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top