• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 630
  • Last Modified:

Global template macro after document open

below is the macro code for a template stored in the startup folder.

My probem is on certin already set templates I get the error message "This Command is not available because no document is open"  Is there a way arround this?  Or is there a way to run this macro after a document the document is open?

Thanks
Adam
---------------------------------------------------------------------
Sub New_Macro()
   MsgBox "This is a global macro test."
End Sub

Sub AutoExec()
    Dim oMainMenu As CommandBar
    Dim myCtrl As CommandBarControl
    For Each myCtrl In CommandBars("File").Controls
        If myCtrl.Caption = "New Macro" Then
            myCtrl.Delete
        End If
    Next
    set myCtrl=Nothing
    If ActiveDocument <> ThisDocument Then
        Set oMainMenu = ActiveDocument.CommandBars("File")
        oMainMenu.Controls.Add(Type:=msoControlButton, Before:=6).Caption = "New Macro"
        oMainMenu.Controls("New Macro").OnAction = "New_Macro"
    End If
End Sub
0
aboskoco
Asked:
aboskoco
  • 5
  • 5
1 Solution
 
GrahamSkanRetiredCommented:
It is possible to redefine the query SQL, so that the mail merge selects a different recordset. This would involve asking the value of different parameters via a UserForm, inserting the parameters into the SQL string, and redefining the source as the new string.
0
 
aboskocoAuthor Commented:
thanks, but there's no SQL involved.  I am just looking for a way arround the AutoExec() function.  
0
 
GrahamSkanRetiredCommented:
Sorry that answer was meant for a totally different question.
0
Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
GrahamSkanRetiredCommented:
I can't reproduce your problem, but have you tried using the Document_Open event?
0
 
gilbarCommented:
what do you want it to do if there's no document open? how about:

If ActiveDocument <> ThisDocument  and Application.Documents.Count > 0 Then
'rest of stuff


which would only do the toolbar stuff IF it wasn't ThisDocument and there was a document open.

Or (like Graham said)
switch it to a Sub AutoOpen (or Document_Open event) instead of AutoExec
0
 
aboskocoAuthor Commented:
I tried using the Document_Open but I don't believe this function works on global macro's.  AutoOpen - eaither I am coding it wrong or it doesn't work.

hmmm.....
0
 
aboskocoAuthor Commented:
figured it out.
AutoExec() will run as a template in the templates folder, as an add in to Normal.dot, this will occur after document open.  Error is no longer a problem
Thanks

0
 
aboskocoAuthor Commented:
Thanks for giving this one a shot.

Moderator, Please close

0
 
GrahamSkanRetiredCommented:
abosoko,
If you don't want to close the question yourself, you can request that it be closed via a points-free question in the Community support area - follow the Support link at the top of the page.
0
 
aboskocoAuthor Commented:
Your extra help should be rewarded. Even after I was going to close with no points  :)
0
 
GrahamSkanRetiredCommented:
OK, You're the boss. Thanks
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

  • 5
  • 5
Tackle projects and never again get stuck behind a technical roadblock.
Join Now