Solved

Global template macro after document open

Posted on 2006-06-30
11
605 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
Comment Utility
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
Comment Utility
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
Comment Utility
Sorry that answer was meant for a totally different question.
0
 
LVL 76

Expert Comment

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

Expert Comment

by:gilbar
Comment Utility
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
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 

Author Comment

by:aboskoco
Comment Utility
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
Comment Utility
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
Comment Utility
Thanks for giving this one a shot.

Moderator, Please close

0
 
LVL 76

Accepted Solution

by:
GrahamSkan earned 500 total points
Comment Utility
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
Comment Utility
Your extra help should be rewarded. Even after I was going to close with no points  :)
0
 
LVL 76

Expert Comment

by:GrahamSkan
Comment Utility
OK, You're the boss. Thanks
0

Featured Post

What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Like many others, we try and discourage users from printing documents unnecessarily and instead send or share them electronically. However, this doesn't always work and documents are still printed. With this simple solution, if the user tries to …
Introduction This tutorial provides instructions on how to properly format your Word document using the inbuilt tools provided. The benefits of using these tools means your documents are more accessible and easily portable to other applications an…
This video shows where to find templates, what they are used for, and how to create and save a custom template using Microsoft Word.
Office 365 is currently available in five editions. Three of them are for business use: Office 365 Business Essentials, Office 365 Business, and Office 365 Business Premium. Two of them are for home/personal use: Office 365 Home and Office 365 Perso…

763 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

13 Experts available now in Live!

Get 1:1 Help Now