Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Word Macros

Status
Not open for further replies.

christer99

IS-IT--Management
Dec 3, 2001
247
Hi!

Have created Word Macros that is pre-filling a text document with a prospect name, etc, but can't get them format properly in a text paraphgraph. It seems that the last letter is cut off and/or it looks like the text is out of alignment (too high). I have tried to fix for 5 hours, and I am about to give up. I am using Autoformat and I have made suze the font size is the same as the rest of the paragraph.
 
Hi,

Here is the code. I am not if this is a code issue or not. Again, the text that is being inserted is part of a paragraph, like inserting a persons's name in a long sentence. However, it seems whatever I do, the inserted text is 1 or 2 pixels too high (not aligned). I have it set as auto size, which I have to do because the length of the person's name can vary.

Private Sub CommandButton11_Click()


ProspectName = ProspName
FullName2 = FirstName + " " + LastName
Label2 = ProspName
End Sub

Private Sub Label2_Click()

End Sub
 
Holler if I'm wrong but it seems that you have controls on your Word document (labels and such).

And, instead of inserting the text directly into the text of the document, you are setting the captions of your controls.

What I suspect is that your labels are too short
"It seems that the last letter is cut off"

and they (your controls) are not positioned properly with regards to the baseline of the document's text
"it looks like the text is out of alignment (too high)"
 
You are correct in your assumption that I am using labels in a word document. However, I have really tried for hours to get this to work, such as positioning them properly with regards to the baseline of the text document. If I adjust it perfectly, and then I enter another name for the prospect name, and then "everything changes"... all of a sudden it is out of alignment again... I can't go and change the label alignment after everytime I do this... the name is mentioned in a bunch of places, plus there is other information that I am inserting. I suspect the out of alignment is due to the auto size, but if I don't use autosize (autoresize?) it is impossible to get the width perfect. I know there is probably a smarter way to do what I am trying to do. Anybody that knows a good website that deal with both Word & Visual Basic? What I really would like to do is to create a pop up window where all the information is entered, and the data is being inserted into the word document. Or maybe a button off the Word navigation bar.
Any ideas would be appreciated.
 
You could insert bookmarks in your Word document where you want the text to be inserted.
Then you could, to insert your text, use something like...

Sub test()
Dim oDoc As Document
Dim oRange As Range

Set oDoc = ActiveDocument

Set oRange = oDoc.Bookmarks("firstname").Range
oRange.Text = "Justin"
Set oRange = Nothing

Set oRange = oDoc.Bookmarks("surname").Range
oRange.Text = "Ezequiel"
Set oRange = Nothing

Set oDoc = Nothing
End Sub
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top