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 wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

MS Word 2007 Automation

Status
Not open for further replies.

cs2009

Programmer
Aug 10, 2009
50
US
Using Visual Basic 2008.

Below is a code snippet I use to automate Word:
Code:
strLetter.Append("John Smith")
strLetter.Append(Environment.NewLine)
strLetter.Append("1 Main Street")
strLetter.Append(Environment.NewLine)
strLetter.Append("Any Town")
strLetter.Append(Environment.NewLine)

oWord.Selection.TypeText(strLetter.Text.ToString())

I use the same formatting with the NewLine to produce a pdf file, and this works fine. When I produce the Word document each NewLine is treated was a paragraph and the results is too much space between lines. The Word output looks like this:

Code:
John Smith

1 Main Street

Anytown

instead of this

Code:
John Smith
1 Main Street
Anytown

Can someone help me?
 

Try using vbCR instead of Environment.Newline.

I used to rock and roll every night and party every day. Then it was every other day. Now I'm lucky if I can find 30 minutes a week in which to get funky. - Homer Simpson

Arrrr, mateys! Ye needs ta be preparin' yerselves fer Talk Like a Pirate Day!
 
Thanks but I already tried vbCr and vbLf. Same result.
 
Not sure bout this, but you can give it a try:
Code:
strLetter.Append("John Smith" & Environment.NewLine)

Good luck.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top