Access to Word then Format (1 Viewer)

SikSlk

Registered User.
Local time
Tomorrow, 02:15
Joined
Aug 30, 2006
Messages
39
Hi All
Quick note: I had a search and couldn't find much (pretty rare on this site) and also I wasn't sure which topic this fell under so please move if needed, sorry if so.

Anyway, Question:

I use a form to move alot of data from a record into a word template using a series of strings put together automatically then moved into bookmarks.

Everything is all fine, however I am now trying to format two lines(if conditions are right) to be bold.

from searching i have:
Code:
Set r = doc.Range
r.Start = doc.Bookmarks("PartsBM").Range.Start

With r.Find
    .Text = "Option 1 - Heater inserts only"
    .ClearFormatting
    .Execute warp:=wdFindStop, Replace:=wdReplaceAll
End With
Selection.Find.Execute
Selection.Font.Bold = True

but honestly have no idea how to go about it, ie selecting the bm then finding the line then setting format to = bold.

Thanks for any information or direction :)
 
Last edited:
M

Mike375

Guest
If no answer is forthcoming you could do what I do and that is to use more than one Word.doc. The following is the code I use down to the point just before the "insert into bookmarks" starts and as you can see an Access entry on the record is determining which Word.doc is opened. If you use this method then just make a copy of your Word.doc and in the copy format the bookmarks in question to bold.

Dim WordObj As Word.Application
Dim WordDoc As Word.Document
Dim WordRange As Word.Range
Set WordObj = CreateObject("Word.Application")

If [Forms]![12ProspectT]![Diary] = 10 Then
Set WordDoc = WordObj.Documents.Open _
("C:\Letters\SoA.doc")

Else

Set WordDoc = WordObj.Documents.Open _
("C:\Letters\SoAMike.doc")

End If

WordObj.Visible = True
 

Pat Hartman

Super Moderator
Staff member
Local time
Today, 12:15
Joined
Feb 19, 2002
Messages
43,474
If you are trying to format text that you inserted at a bookmark, just format it while you already have it selected. If the text is in the template, I can't help you but what I would do is open the template and try to perform the action with the macro recorder open. You can then look at the code generated by the macro recorder and copy what you need.
 

SikSlk

Registered User.
Local time
Tomorrow, 02:15
Joined
Aug 30, 2006
Messages
39
Thanks for your comments, im still stuck though.

The text that is inserted is string that access generats which comes out looking like a title and then a paragraph. but can be two of these linked into the one string resulting in two heading and two paragraps been inserted into the one bookmark.

this is the code i have so far, it selects the whole page (couldn't select the bookmark without errors, but let me know of another way) but before finding the text stops at an error object required.

If been using trail and error to get this far so let me know of any other direction i can take but this is the closest iv been.

Code:
With doc.Range.Select
    .Selection.Find.ClearFormatting
    With .Selection.Find
       .Text = "Option 1 - Heater inserts only"
       .Replacement.Text = ""
       .Forward = True
       .Wrap = wdFindContinue
       .Format = False
       .MatchCase = False
       .MatchWholeWord = False
       .MatchWildcards = False
       .MatchSoundsLike = False
       .MatchAllWordForms = False
    End With
    .Selection.Find.Execute
    If Selection.Find.Found = True Then
       Selection.Font.Bold = True
    End If
    End With
 
Last edited:

Pat Hartman

Super Moderator
Staff member
Local time
Today, 12:15
Joined
Feb 19, 2002
Messages
43,474
When you insert the text at the bookmark, it is already selected so you don't need to select it again.
 

Users who are viewing this thread

Top Bottom