Celebrate National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Global template macro after document open

Posted on 2006-06-30
11
Medium Priority
?
614 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Important Lessons on Recovering from Petya

In their most recent webinar, Skyport Systems explores ways to isolate and protect critical databases to keep the core of your company safe from harm.

 
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
 

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 2000 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

[Webinar] Protection from Cyberattacks

In this session, we’ll dive into the complexities of modern cyber threats and why only multi-vector protection can keep today’s businesses secure through the various stages of a cyberattack, across multiple vectors. Thursday September 14, 2017 10:00 A.M. PDT

Question has a verified solution.

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

The Selection object is designed for user interaction. It has a Range property, so it can be used in most places that a Range object can. Recorded macros must use the Selection because they are simply copying what the user is doing. A Range prope…
I would like to show you some basics you can do with Mailings in MS Word. It´s quite handy feature you can use for creating envelopes, labels, personalized letters etc. First question could be what is this feature good for? Mailing can really he…
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) …
This video teaches the viewer how to align pictures around text while keeping the text properly aligned in the document.

730 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