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
aboskocoAsked:
Who is Participating?
 
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
 
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
Cloud Class® Course: Amazon Web Services - Basic

Are you thinking about creating an Amazon Web Services account for your business? Not sure where to start? In this course you’ll get an overview of the history of AWS and take a tour of their user interface.

 
GrahamSkanRetiredCommented:
Sorry that answer was meant for a totally different question.
0
 
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
 
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.

All Courses

From novice to tech pro — start learning today.