Help with word Macro

T

Tith

I'm in need of a macro to help me format upwards of 10000 word files. I have
the two macros I will need to format each word doc, but I would like to
automate this further by running it on a directory (including
sub-directories). I'm not very familar with VBA so I'm stumbling through it.

these reports will either have 4 or 5 inline images and each will have to be
treated a little dirfferently. I have created the macros for those two
situations.

Sub ChooseMacro()
'
' Macro3 ChooseMacro
' Macro created 3/24/2010 by tith
' Determines which macro to run, Macro1() or Macro2()
'
Dim iShapeCount As Integer
Dim tmpMsg As String
Set ThisDoc = ActiveDocument

iShapeCount = ThisDoc.InlineShapes.Count

If iShapeCount = 4 Then
' How do I call a macro inside a macro?
' Macro1()
tmpMsg = "Run Macro1()"
MsgBox (tmpMsg)
ElseIf iShapeCount = 5 Then
' How do I call a macro inside a macro?
' Macro2()
tmpMsg = "Run Macro2()"
MsgBox (tmpMsg)
Else
' Do nothing

End If

End Sub
 
P

Pesach Shelnitz

Hi,

To call a macro from a macro, just write the name of the macro to be called.
For example, in the following two macros, when you run Macro1, it calls Macro
2.

Sub Macro1()
Macro2
End Sub

Sub Macro2()
MsgBox ("Hello World")
End Sub

You can also add the keyword Call before Macro2 in Macro1.
 
G

Greg Maxey

If, as it sort of appears, you are trying to get a result from Macro1 or
Macro2 then you would use a Function:

Sub ChooseMacro()
Dim iShapeCount As Integer
iShapeCount = ActiveDocument.InlineShapes.Count
Select Case iShapeCount
Case Is = 4
MsgBox Macro1
Case Is = 5
MsgBox Macro2
Case Else
'Do nothing
End Select
End Sub

Function Macro1() As String
Macro1 = "I'm Macro1 result"
End Function

Function Macro2() As String
Macro2 = "I'm Macro2 result"
End Function
 
T

Tith

Thanks the link was very helpful.

I know what I wanted to do, but I wasn't sure how to go about it in VBA.
Thank you!
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top