While running macro, prompt for name of another macro and run it t

L

LDMueller

In Word 2003 I have a macro which creates a letter. I need this macro to
prompt for another macro which will allow us to put in a specific attorney
signature block with all the attorney's information.

Is this possible and if so can someone help me with the code for the latter
part.

Thanks,

LDMueller
 
J

Jay Freedman

LDMueller said:
In Word 2003 I have a macro which creates a letter. I need this
macro to prompt for another macro which will allow us to put in a
specific attorney signature block with all the attorney's information.

Is this possible and if so can someone help me with the code for the
latter part.

Thanks,

LDMueller

It would be possible to do this with the Application.Run method (which is
covered in the VBA help).

However, it would be easier and more maintainable to store each entire
signature block as an AutoText entry in the document template, and have the
(one and only) macro insert the proper entry for the current attorney.

For example, if the string variable strAtty contains the name of the proper
AutoText entry (which may be the attorney's name, although it could be some
other identifier), this will insert the signature block from that entry at
the insertion point:

With ActiveDocument.AttachedTemplate
.AutoTextEntries(strAtty).Insert _
Where:=Selection.Range, RichText:=True
End With

--
Regards,
Jay Freedman
Microsoft Word MVP
Email cannot be acknowledged; please post all follow-ups to the newsgroup so
all may benefit.
 
L

LDMueller

Hi Jay,

Thank you for your prompt response. Unfortunately, I cannot use the
AutoText entry in the document template because I still have to have it
prompt for the attorney's initials depending on the secretary running the
macro. In addition the signature prompts for Enclosures, etc. Here's my
code below.

Selection.TypeText Text:=vbTab & vbTab & "Sincerely,"
Selection.TypeParagraph
Selection.TypeParagraph
Selection.TypeParagraph
Selection.TypeParagraph
Selection.TypeText Text:=vbTab & vbTab & "John Doe"
Selection.TypeParagraph
Selection.TypeParagraph
Selection.TypeText Text:="JD/"
Selection.Fields.add Range:=Selection.Range, Type:=wdFieldEmpty, Text:= _
"FILLIN ""Secretary's initials""", PreserveFormatting:=True
Selection.TypeParagraph
Selection.Fields.add Range:=Selection.Range, Type:=wdFieldEmpty, Text:= _
"FILLIN ""*Enclosure(s) or OK""", PreserveFormatting:=True
Selection.HomeKey Unit:=wdStory
Selection.MoveDown Unit:=wdLine, Count:=1
Selection.ParagraphFormat.TabStops(InchesToPoints(0)).Position = _
InchesToPoints(5.08)
With Selection.ParagraphFormat
.LeftIndent = InchesToPoints(5)
.SpaceBeforeAuto = False
.SpaceAfterAuto = False
End With
With Selection.ParagraphFormat
.RightIndent = InchesToPoints(-0.5)
.SpaceBeforeAuto = False
.SpaceAfterAuto = False
End With
Selection.Font.Name = "BankGothic Md BT"
Selection.Font.Size = 7
Selection.TypeParagraph
Selection.TypeText Text:="John Doe"
With Selection.ParagraphFormat
.LeftIndent = InchesToPoints(5)
.RightIndent = InchesToPoints(-0.5)
.SpaceBefore = 0
.SpaceBeforeAuto = False
.SpaceAfter = 0
.SpaceAfterAuto = False
.LineSpacingRule = wdLineSpace1pt5
.Alignment = wdAlignParagraphLeft
.WidowControl = True
.Hyphenation = True
.FirstLineIndent = InchesToPoints(0)
.OutlineLevel = wdOutlineLevelBodyText
.CharacterUnitLeftIndent = 0
.CharacterUnitRightIndent = 0
.CharacterUnitFirstLineIndent = 0
.LineUnitBefore = 0
.LineUnitAfter = 0
End With
Selection.TypeParagraph
Selection.TypeText Text:="Doe Management Corporation"
With Selection.ParagraphFormat
.LeftIndent = InchesToPoints(5)
.RightIndent = InchesToPoints(-0.5)
.SpaceBefore = 0
.SpaceBeforeAuto = False
.SpaceAfter = 0
.SpaceAfterAuto = False
.LineSpacingRule = wdLineSpaceSingle
.Alignment = wdAlignParagraphLeft
.WidowControl = True
.Hyphenation = True
.FirstLineIndent = InchesToPoints(0)
.OutlineLevel = wdOutlineLevelBodyText
.CharacterUnitLeftIndent = 0
.CharacterUnitRightIndent = 0
.CharacterUnitFirstLineIndent = 0
.LineUnitBefore = 0
.LineUnitAfter = 0
End With
Selection.TypeParagraph
Selection.TypeText Text:="100 NORTH MAIN"
Selection.TypeParagraph
Selection.TypeText Text:="COLLINSVILLE, ILLINOIS 62234"
With Selection.ParagraphFormat
.LeftIndent = InchesToPoints(5)
.RightIndent = InchesToPoints(-0.5)
.SpaceBefore = 0
.SpaceBeforeAuto = False
.SpaceAfter = 0
.SpaceAfterAuto = False
.LineSpacingRule = wdLineSpace1pt5
.Alignment = wdAlignParagraphLeft
.WidowControl = True
.Hyphenation = True
.FirstLineIndent = InchesToPoints(0)
.OutlineLevel = wdOutlineLevelBodyText
.CharacterUnitLeftIndent = 0
.CharacterUnitRightIndent = 0
.CharacterUnitFirstLineIndent = 0
.LineUnitBefore = 0
.LineUnitAfter = 0
End With
Selection.TypeParagraph
Selection.TypeText Text:="(814) 445-1234"
Selection.TypeParagraph
Selection.TypeText Text:= (e-mail address removed)"
Selection.TypeParagraph
Selection.TypeText Text:="DOE.COM"
ActiveWindow.ActivePane.View.ShowAll = Not ActiveWindow.ActivePane.View. _
ShowAll
Selection.MoveRight Unit:=wdCharacter, Count:=1
Selection.Delete Unit:=wdCharacter, Count:=1
Selection.Delete Unit:=wdCharacter, Count:=1
Selection.Delete Unit:=wdCharacter, Count:=1
Selection.HomeKey Unit:=wdStory
End Sub

If I use the Application.Run method how do I get it to prompt for the
attorney's initials so it can run the right macro?

You help is so greatly appreciated.

LDMueller
 
J

Jay Freedman

Words cannot express how sad it makes me to see huge gobs of code taken verbatim
from the macro recorder, including all the default settings that don't have any
effect. This sort of thing is why I wrote
http://www.word.mvps.org/FAQs/MacrosVBA/ModifyRecordedMacro.htm.

It also hurts my eyes to see the use of multiple paragraph marks instead of
Space Before or Space After paragraph formatting, and various other explicit
cursor movements.

But it's especially painful that almost everything done by code in this macro
should simply be put into the body of the template, so it will automatically
appear in every new document based on the template. You don't need a macro at
all for this part of the job. See
http://sbarnhill.mvps.org/WordFAQs/Letterhead.htm for the basics of this
approach.

If you want the macro to ask the secretary to enter the attorney's initials
(which might uniquely identify the attorney, but only if no two attorneys in the
firm have the same initials), use an InputBox statement:

Dim strAtty As String
strAtty = InputBox("Enter attorney's initials")

Of course, it would then be a good thing to compare the result to a known list
of valid initials to make sure the secretary didn't mistype, and to make sure
the value isn't an empty string.

If the signature blocks are stored in AutoText entries, and the name of each
entry is that attorney's initials, then the code I showed before will work to
insert the correct block.
 
J

Jules

Why don't you allow the user just to type the attorney initials ABC or DEFG
and press F3 key which plays the autotext entry when they are ready to sign
off?
"Enc" is typed quicker or deleted if in the signature block after user has
typed the letter when one actually knows there is an enclosure.

For your consideration...
 
D

Dorak

I ran into this about a year and a half ago, while creating pleading
templates for one or more signing attorneys. I have no idea what the experts
will say as to my solution, and I might be very sorry I posted this, but here
is the gist of it anyway.

In a user form called "TwoSig", create a combo box for attorney one (cboA1)
and require an exact match. Then in a separate application (Att1), populate
the bookmarks with appropriate text based on contents of cboA1.

In the control button for the user form, run Att1 when appropriate, and run
Att1 immediately after.

I had to do this for 54 attorneys, and while it was time consuming, it was
well worth the effort.

Sub Att1()
'get contents of cboA1 and populate bookmarks
'A1, Phone, and E1 where "xxx" equals attorney initials,
'"00000" equals phone extension, and "attorney email" equals
'attorney's email address
'Template contains the area code and prefix for phone number and
'@lawfirm.com, so only the extension and user's email name are needed.

With ActiveDocument
If TwoSig.cboA1 = "xxx" Then
.Bookmarks("A1").Range.Text = "Attorney Name (#00000)"
.Bookmarks("Phone").Range.Text = "00000"
.Bookmarks("E1").Range.Text = "attorney email"
End If

'continue with each attorney

End With
End Sub

Then all you have to do is copy cboA1 and name it cboA2.
Then copy Att1 macro , and simply replace "1" with "2".

If one signing attorney, it will pull that attorney's full name and bar
i.d., phone number and email address.

If two signing attorneys, it will pull each attorney's full name and bar
i.d., the general firm telephone number, and each attorney's address (the
more senior attorney appears first).

With slight modifications, I can use this in a variety of templates, and
there's very little work to do to update it with incoming our outgoing
attorneys.

Also: It took me a while to understand enough of Visual Basic that cleaning
up extraneous default settings is important "housekeeping", but with the help
of this group and other MVPs, I'm getting better at automating Word and I
thank all of the experts here for input and encouragement.

And Also: It has been an ongoing struggle for me to get users to accept that
formatting the paragraphs correctly and use of styles are best practices, but
now that they are using the such nice clean templates I've made for them,
they are being won over.
 
L

LDMueller

Thank you for your information. I've taken everything you've mentioned into
consideration.

I understand the cleanup of the codes and the possibility of using autotext
and styles. No matter what we have tried, we cannot get our users to use
styles so that's not an option here.

My macro is suppose to take an existing letter, put the sincerely and
attorney name (signature block) at the end of the letter, go back to the top
and insert our letterhead graphic which is generic and then on the righthand
side, put the attorney's name, email address and their phone number.

Below is my autotext version of the above. I did include the fillin prompts
in the autotext and this I'm not sure is correct and will need confirmation
that this is okay to do.

Sub FRA()
Selection.Find.Text = "SignBlock"
If Selection.Find.Execute = True Then
Selection.Delete Unit:=wdCharacter, Count:=1
Else
Selection.EndKey Unit:=wdStory
End If

NormalTemplate.AutoTextEntries("FRASignatureBlock").Insert
Where:=Selection.Range, RichText:=True
Selection.HomeKey Unit:=wdStory
NormalTemplate.AutoTextEntries("FRALtrHead").Insert
Where:=Selection.Range, RichText:=True
' Selection.HomeKey Unit:=wdStory
NormalTemplate.AutoTextEntries("LtrHead").Insert Where:=Selection.Range,
RichText:=True
Selection.HomeKey Unit:=wdStory
End Sub

I also have a cleaned up version of my original code which is quite
condensed. Since the autotext and the macros are both kept in the
normal.dot, is there any reason to design one way over the other?

Thank you for your help.

LDMueller
 
D

Dorak

Sorry about that....told you I'd probably be sorry. However, because I work
in network with over 150 users and 4 office locations, autotext not an option
because we do not have a global.dot and not good to write to anyone's
normal.dot.

I do have a neat trick for signatures and autotext....each auto signature
could be .xxx where xxx is the user's initials, the preceding period could
help keep autotext from producing an undesirable result -- for what it's
worth.
 

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