Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
DiscussionsAccessExcelInfoPathOutlookPowerPointPublisherWord
DirectoryUser Groups
Related Topics
Outlook ExpressInternet ExplorerWindowsMS Server ProductsMore Topics ...

MS Office Forum / Word / Programming / September 2007

Tip: Looking for answers? Try searching our database.

Calling a macro

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Elaine J. - 12 Sep 2007 00:14 GMT
I have a VBA macro that I am using and I want to call another macro.  I have
been tried the two versions of calling a macro below.

Application.Run MacroName:="[PrintHRFormsRep]"
Application.Run "'Shreveport.doc'!NOH.PrintHRFormsRep"

But I keep getting an error message that says:

Unable to run the specified macro.  

The document that I am working in has a range set called noticeplus.  Then I
want to call a macro that will open another document, print it, close it and
revert back to the previous active document.  Both macros work independently,
but I want to be able to use them together.  

It occurred to me on the way home tonight that maybe it had something to do
with the range being set.  Is there another way to call a macro when a range
is set?

Both macros are in the same template and module.

Thanks for any help.
Greg Maxey - 12 Sep 2007 00:24 GMT
Sub ScratchMacro()
Dim oRng As Word.Range
Set oRng = Selection.Range
Test
Call Test
Application.Run MacroName:="Test"
Application.OnTime When:=Now + TimeValue("00:0:02"), Name:="Test" 'runs in 2
seconds
End Sub
Sub Test()
MsgBox "Eureka"
End Sub

Signature

Greg Maxey/Word MVP
See:
http://gregmaxey.mvps.org/word_tips.htm
For some helpful tips using Word.

> I have a VBA macro that I am using and I want to call another macro.
> I have been tried the two versions of calling a macro below.
[quoted text clipped - 18 lines]
>
> Thanks for any help.
Elaine J. - 12 Sep 2007 01:06 GMT
Greg, for some reason, this has just confused me.  I'm sure it relates to
what I am trying to do, but I can't see it just yet.

I have a range called noticeplus, A macro named PrintNOH and I want to call
another macro called printhrformsRep.  How do I translate what you have to
that?  i.e. is what you are calling test where I would put the
printhrformsrep macro?  Do I need to declare any additional variables?  For
instance the word TEST on a line by itself doesn't make sense to me. (But
then, I'm pretty much a beginner in this, so that is probably why.)

Thanks for your help

> Sub ScratchMacro()
> Dim oRng As Word.Range
[quoted text clipped - 31 lines]
> >
> > Thanks for any help.
Greg Maxey - 12 Sep 2007 01:12 GMT
Elaine,

Sorry for confusing you.  I took for granted that you would copy the code
into your VB Editor and run it to see what happened ;-)

"Test" is the macro that I am calling from ScratchMacro.  I simply showed
you four different was that I could call it.

1. Test
2. Call Test
3. Application.Run MacroName:="Test"
4. Application.OnTime When:=Now + TimeValue("00:0:02"), Name:="Test"

I set oRng to the selection range just to show you that has nothing to do
with calling a macro.

Copy the code I sent you into your editor and select the Run method.  Then
press F1.  The help file and examples may clear things up.

Signature

Greg Maxey/Word MVP
See:
http://gregmaxey.mvps.org/word_tips.htm
For some helpful tips using Word.

> Greg, for some reason, this has just confused me.  I'm sure it
> relates to what I am trying to do, but I can't see it just yet.
[quoted text clipped - 51 lines]
>>>
>>> Thanks for any help.
Elaine J. - 12 Sep 2007 01:42 GMT
Greg, thanks so much.  I think I can see my error now.  I was using this
format  Application.Run MacroName:="[PrintHRFormsRep]" (from a sample that I
was looking at.).  It looks like I need to remove the brackets.

I appreciate your help.

> Greg, for some reason, this has just confused me.  I'm sure it relates to
> what I am trying to do, but I can't see it just yet.
[quoted text clipped - 43 lines]
> > >
> > > Thanks for any help.
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.