Mr_Fulano
asked on
Macro Variable Question
Hi, I have a Macro in MS Word 2003 that gets a string value from the Windows Registry and puts that value into a String variable. I can output my variable to a message box, but I want to place the value into my document instead.
How do I get a variable from my Macro into my current document. -- Let's assume my variable is called: myStringValue and it contained the String "MS Word 2003".
I would like to have my document contain the variable String "MS Word 2003" in it.
Not sure how to do that...
Thank you for your help,
Fulano
How do I get a variable from my Macro into my current document. -- Let's assume my variable is called: myStringValue and it contained the String "MS Word 2003".
I would like to have my document contain the variable String "MS Word 2003" in it.
Not sure how to do that...
Thank you for your help,
Fulano
you can also write your value directly without making an active tag
with the world object to write in the document
i used it in outlook to add a signature when outlook had word as editor
here is an example:
dont forget, its from outlook, might need a few modifications
with the world object to write in the document
i used it in outlook to add a signature when outlook had word as editor
here is an example:
dont forget, its from outlook, might need a few modifications
Sub sign()
'=== replace in word object editor
Dim objDoc As Word.Document
Dim objSel As Word.Selection
Dim a As Variant
'On Error Resume Next
'=== get a Word.Selection from the open Outlook item
Set objDoc = Application.ActiveInspector.WordEditor
Set objSel = objDoc.Windows(1).Selection
Call ini_dep
'=== now do what you want with the Selection
' .Name = "Times New Roman"
' .Size = 10
' .Bold = False
' .Italic = False
' .Underline = wdUnderlineNone
' .UnderlineColor = wdColorAutomatic
' .Strikethrough = False
' .DoubleStrikeThrough = False
' .Outline = False
' .Emboss = False
' .Shadow = False
' .Hidden = False
' .SmallCaps = False
' .AllCaps = False
' .Color = wdColorAutomatic
' .Engrave = False
' .Superscript = False
' .Subscript = False
' .Spacing = 0
' .Scaling = 100
' .Position = 0
' .Kerning = 0
' .Animation = wdAnimationNone
objSel.Font.Name = "Arial"
objSel.Font.Size = 10
If usenam = "fournier.serge" Then
a = "Serge Fournier, Prog./Analyst, département des TI" & vbCrLf
objSel.TypeText a
objSel.Font.Bold = True
a = "STAS Inc." & vbCrLf
objSel.TypeText a
objSel.Font.Bold = False
a = "999 ABC: & vbCrLf
a = a & "Tél.: 111-111-111, ext. 1111" & vbCrLf
a = a & "Fax 1: 111-111-1111, Fax 2: 111-111-1111" & vbCrLf
a = a & "Adresse électronique(Email): mailto: abc@bca.zzz" & vbCrLf
a = a & "MSNLIVE: msnim:add?contact=zzz.aaa.ccc.zzz@live.zz" & vbCrLf & vbCrLf
objSel.TypeText a
End If
objSel.Font.Name = "Arial"
objSel.Font.Size = 7.5
a = "Avis de confidentialité. La présente communication est confidentielle et transmise sous le sceau du secret professionnel. Si vous n'êtes pas le destinataire visé ou son mandataire chargé de lui transmettre cette communication, vous êtes par la présente avisé qu'il est expressément interdit d'en dévoiler la teneur, de la copier, de la distribuer ou de prendre quelque mesure fondée sur l'information qui y est contenue. Si vous avez reçu cette communication par erreur, veuillez nous en aviser immédiatement par téléphone à frais virés et nous retourner l'original par la poste à l'adresse indiquée plus haut." & vbCrLf & vbCrLf
'=== fra
objSel.LanguageID = wdFrenchCanadian
objSel.TypeText a
'=== eng
'objDoc.Bookmarks("\Para").Select
objSel.LanguageID = wdEnglishUS
a = "Confidential Information. This communication and any attachments are private and may contain legally privileged information. If you are not the authorized recipient, the copying or distribution of this communication or any attachments is prohibited and you must not read, print or act in reliance of this communication. If you have received this communication by mistake, we would appreciate if you could advise us collect call and mail the document at the address indicated above." & vbCrLf
objSel.TypeText a
objSel.LanguageID = wdFrenchCanadian
Set objDoc = Nothing
Set objSel = Nothing
oops all my hpone numbers and email are in there hehe
ah well... as long as i did not put any passwords ;)
ah well... as long as i did not put any passwords ;)
wildboy85:
I have posted a request via the request attention button for you
Chris
I have posted a request via the request attention button for you
Chris
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thank you all...this note will cover my comments to you all.
Lee555J5, I tried your way, but found that I could not make it work. Its probably a good way, but I had trouble with it.
WildBoy85, although I'm sure you way is a good way as well, it was a bit too much for me to follow. I got a little lost.
GrahamSkan's approach was simple and gave me what I needed. - I only have a coulpe of questions before I close the post.
GrahamSkan: once you have the Bookmark set where you want it, how do you move beyond it? The space bar just pushed it forward and doesn't step over it. Also, is there a way to see where the Bookmarks are set?
Thanks to all,
Fulano
Lee555J5, I tried your way, but found that I could not make it work. Its probably a good way, but I had trouble with it.
WildBoy85, although I'm sure you way is a good way as well, it was a bit too much for me to follow. I got a little lost.
GrahamSkan's approach was simple and gave me what I needed. - I only have a coulpe of questions before I close the post.
GrahamSkan: once you have the Bookmark set where you want it, how do you move beyond it? The space bar just pushed it forward and doesn't step over it. Also, is there a way to see where the Bookmarks are set?
Thanks to all,
Fulano
ASKER
GrahamSkan in addition to the questions above, I noticed that regardless where I put the Bookmark, my value always gets inserted at the end of my document. Is there a way to change that and have it insert into the body of the document where I've placing my Bookmark?
Thanks,
Fulano
Thanks,
Fulano
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
I don't really understand the query about the spacebar.
There is an option to make the user-added bookmark positions visible (Tools>Options>View tab). The beginning and end look like [grey square brackets]. Or you can use Edit/GoTo to locate one by name.
There is an option to make the user-added bookmark positions visible (Tools>Options>View tab). The beginning and end look like [grey square brackets]. Or you can use Edit/GoTo to locate one by name.
ASKER
GrahamSkan and Chris, thank you both for your help. Chris hit the nail on the head when he suggested replacing the "\EndOfDoc" with my Bookmark. I had tried to do that at first, but I did -- "\myBookmark" instead of just "myBookmark". It works out well.
Thank you both for your help.
Fulano
Thank you both for your help.
Fulano
ASKER
Thank you both. You were both very helpful.
In your macro code, add this line
Lee