inserting two text blocks with different formats in Word from Excel

A

ajaypondicherry

I am creating a Microsoft Excel Spreadsheet which launches a Word Doc
and would like to make a document title in a certain format and below
it make the body text with another format. It seems as if both texts
always use the same formatting. Below is a section of my code.

With mywdRange
.Text = Range("F6") & " Title" & " Text"
.Font.Name = "Comic Sans MS"
.Font.Size = 20
.Bold = True
End With

With mywdRange
.Text = Range("F6") & " Body" & " Text"
.Font.Name = "Comic Sans MS"
.Font.Size = 12
.Bold = False
End With
 
J

Jonathan West

I am creating a Microsoft Excel Spreadsheet which launches a Word Doc
and would like to make a document title in a certain format and below
it make the body text with another format. It seems as if both texts
always use the same formatting. Below is a section of my code.

With mywdRange
.Text = Range("F6") & " Title" & " Text"
.Font.Name = "Comic Sans MS"
.Font.Size = 20
.Bold = True
End With

With mywdRange
.Text = Range("F6") & " Body" & " Text"
.Font.Name = "Comic Sans MS"
.Font.Size = 12
.Bold = False
End With

Both bits of code appear to be operating on the same range. Is there some
other bit of code between them that you haven't shown us, where the location
pointed to by mywdRange changes?


--
Regards
Jonathan West - Word MVP
www.intelligentdocuments.co.uk
Please reply to the newsgroup
Keep your VBA code safe, sign the ClassicVB petition www.classicvb.org
 
D

Doug Robbins - Word MVP

I would create document variables to contain the text and then have it
appear in the required places in the documnet by use of DOCVARIABLE fields
to which you add the \*charformat switch if necessary to get the desired
format.

With ActiveDocument
.Variables("docvar1").Value = Range("F6") & " Title Text"

.Variables("docvar1").Value = Range("F6") & " Body Text"
.Fields.Update
End With

--
Hope this helps.

Please reply to the newsgroup unless you wish to avail yourself of my
services on a paid consulting basis.

Doug Robbins - Word MVP
 

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