Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 10-31-2011, 05:40 PM
Paulsh Paulsh is offline Call Macro from Input Box String Windows XP Call Macro from Input Box String Office 2010 32bit
Novice
Call Macro from Input Box String
 
Join Date: Oct 2011
Posts: 1
Paulsh is on a distinguished road
Default Call Macro from Input Box String

I am trying to write a macro for Word 2010 to type the name and typist at the end of a letter. I want the typist to the sender's initials such as "jas" in an InputBox and then call the macro "jas" which will then type "John A. Smith." There are multiple initials-name macros that could be called to type the name of a particular sender.

I've been pulling my hair our reading up on and experimenting with "PassByRef" and "Call," etc. and have found 300+ different way not to write the code.

The code would (simply) look like this:
Dim strSender As String
Dim strTypist As String
' selection and cursor movement omitted here for brevity
strSender = InputBox("Enter Sender's Initials:", "SENDER")

Call (strSender)
' it's at this point the "jas" macro would type "John A. Smith"
Selection.TypeParagraph
Selection.TypeParagraph

Selection.TypeText Text:=strSender
Selection.TypeText Text:="/"
strTypist = InputBox("Enter Typist's Initials:", "TYPIST")
Selection.TypeText Text:=strTypist


I did this in WordPerfect years ago by using "nest" and "get." We're converts to all Word now and VBA has me stumped on this one.

Any assistance in solving this dilemma would be greatly appreciated.

Thank you.

Paulsh
Reply With Quote
  #2  
Old 11-01-2011, 03:15 AM
macropod's Avatar
macropod macropod is offline Call Macro from Input Box String Windows 7 64bit Call Macro from Input Box String Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 21,956
macropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond repute
Default

Hi Paulsh,

Have you considered using autotext function? Alternatively, you could store both the initials and names in a single macro:
Code:
Sub AddSender()
Dim StrNames As Variant, StrInits As Variant, StrSender As String, i As Long
StrSender = InputBox("Enter Sender's Initials:", "SENDER")
If StrSender = "" Then Exit Sub
StrInits = Array("mc", "yz", "ar")
StrNames = Array("Michael Carlton", "Yasmin Zanders", "Andy Ryan")
For i = 0 To UBound(StrInits)
  If StrInits(i) = StrSender Then
    Selection.InsertAfter StrNames(i)
    Exit For
  End If
Next
End Sub
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
Reply

Thread Tools
Display Modes


Similar Threads
Thread Thread Starter Forum Replies Last Post
Call Macro from Input Box String Macro VBA "Save as" with bookmarks in file name string Dom37 Word VBA 2 10-31-2011 03:28 AM
Call Excel from Word donlincolnmsof Word 0 10-14-2011 05:02 PM
Help with VBA macro - Variable input sc30317 Excel Programming 0 08-31-2011 01:00 PM
Call Macro from Input Box String Macro or Function to know wether a string is included in a text Eduardo Word VBA 5 06-15-2009 01:55 AM
Call Macro from Input Box String How do I call/execute an Excel macro from Access 2003 KramerJ Excel 2 05-11-2009 11:33 AM

Other Forums: Access Forums

All times are GMT -7. The time now is 03:55 PM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2024, vBulletin Solutions Inc.
Search Engine Optimisation provided by DragonByte SEO (Lite) - vBulletin Mods & Addons Copyright © 2024 DragonByte Technologies Ltd.
MSOfficeForums.com is not affiliated with Microsoft