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

Format Text

Status
Not open for further replies.

tyang01

Technical User
Feb 1, 2007
46
US
Hi, I am trying to format text on a Word document that comes from a Access database. I've tried using the macro recording aspect on Word. But when I transfer the code over to the Access Module it doesn't work.

Here is a sample code.

With objWord.ActiveDocument.Bookmarks
.Item(tbm2).Range.Text = txt2
End With
Select.Style = ActiveDocument.Styles("Heading 1")

Hopefully someone can can help me out.
Thanks in advance.
 
it doesn't work
What happens ? Any error message ? Any line of code highlighted when in debug mode ? Computer crash ? Unexpected behaviour ? ... ?
Anyway, when playing with automation, always use full qualified objects, e.g.:
objWord.Selection.Style = objWord.ActiveDocument.Styles("Heading 1")

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
It ran the code with no errors this time. But it did not enforce the formatting change for some reason.
 
Any chance you could post the recorded (hopefully working) code ?

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
I just changed the one line of code to what you posted. Also if you were wondering (tbm2) is a bookmark string and txt2 is the data which is taken from the database. Yeah it ran all the way through the code without a hitch but it didn't change the format into a heading style.


With objWord.ActiveDocument.Bookmarks
.Item(tbm2).Range.Text = txt2
End With
objWord.Selection.Style = objWord.ActiveDocument.Styles("Heading 1")
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top