Solved

Global template macro after document open

Posted on 2006-06-30
11
607 Views
Last Modified: 2008-01-09
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
Comment
Question by:aboskoco
  • 5
  • 5
11 Comments
 
LVL 76

Expert Comment

by:GrahamSkan
ID: 17020548
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
 

Author Comment

by:aboskoco
ID: 17021223
thanks, but there's no SQL involved.  I am just looking for a way arround the AutoExec() function.  
0
 
LVL 76

Expert Comment

by:GrahamSkan
ID: 17022708
Sorry that answer was meant for a totally different question.
0
 
LVL 76

Expert Comment

by:GrahamSkan
ID: 17022826
I can't reproduce your problem, but have you tried using the Document_Open event?
0
 
LVL 9

Expert Comment

by:gilbar
ID: 17033495
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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 

Author Comment

by:aboskoco
ID: 17044231
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
 

Author Comment

by:aboskoco
ID: 17047032
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
 

Author Comment

by:aboskoco
ID: 17047051
Thanks for giving this one a shot.

Moderator, Please close

0
 
LVL 76

Accepted Solution

by:
GrahamSkan earned 500 total points
ID: 17048769
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
 

Author Comment

by:aboskoco
ID: 17053552
Your extra help should be rewarded. Even after I was going to close with no points  :)
0
 
LVL 76

Expert Comment

by:GrahamSkan
ID: 17053994
OK, You're the boss. Thanks
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Ability to store text on the iPad? 10 73
Using tables with MS Word 16 68
Word - Access 6 55
copy the content of word to outlook 3 48
I'm writing to share my clumsy experience in using this elegant tool so you can avoid every stupid mistake I made. (I leave it to the authorities to decide if this deserves a place in the Knowledge archives.)  Now that I am on the other side of my l…
Microsoft Word is a program we have all encountered at some point, but very few of us have dug deep into its full scope of features, let alone customized it to suit our needs. Luckily making the ribbon (aka toolbar, first introduced in Word 2007) wo…
In this video, we show how to convert an image-only PDF file into a PDF Searchable Image file, that is, a file with both the image (typically from scanning) and text, which is created in an automated fashion with Optical Character Recognition (OCR) …
Learn how to make your own table of contents in Microsoft Word using paragraph styles and the automatic table of contents tool. We'll be using the paragraph styles in Word’s Home toolbar to help you create a table of contents. Type out your initial …

911 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now