Results 1 to 11 of 11
  1. #1
    4 Star Lounger
    Join Date
    Feb 2008
    Location
    United Kingdom
    Posts
    490
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Found Word Font colour (MSACCESS 2003)

    Having returned to some code that I thought worked, I cannot seem to change the font colour of the selected word found. I should have removed some remmed out some lines that refer to colour change as now I don't know the correct syntax for colour, and where it should be put. Also some documents show paragraphs highlighted, and I don't know if my code is causing it or the documents were highlighted and saved by the user. Thanks

    WD.Selection.Find.ClearFormatting
    With WD.Selection.Find
    .Text = Me.List152.Value
    .Replacement.Text = ""
    .Forward = True
    .Wrap = wdFindContinue
    .Format = False
    .MatchCase = False
    .MatchWholeWord = True
    .MatchWildcards = False
    .MatchSoundsLike = False
    .MatchAllWordForms = False

    End With

    Do While WD.Selection.Find.Execute

    ccny = ccny + 1

    If WD.Selection.Find.Found Then


    With WD.Selection.Font
    .Name = "Arial"
    .Size = 12
    .Bold = True
    .Italic = True
    .Underline = wdUnderlineAll 'None
    .UnderlineColor = wdColorAutomatic
    .Strikethrough = False
    .DoubleStrikeThrough = False
    .Outline = False
    .Emboss = False
    .Shadow = False
    .Hidden = False
    .SmallCaps = False
    .AllCaps = True
    .Engrave = False
    .Superscript = False
    .Subscript = False
    .Spacing = 0
    .Scaling = 100
    .Position = 0
    .Kerning = 0
    .Animation = wdAnimationNone
    End With


    WD.Selection.Find.Font.Color = wdColorRed

  2. #2
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Found Word Font colour (MSACCESS 2003)

    You could use

    With WD.Selection.Find
    .ClearFormatting
    .Text = Me.List152.Value
    .Replacement.ClearFormatting
    .Replacement.Text = ""
    .Forward = True
    .Wrap = wdFindContinue
    .Format = False
    .MatchCase = False
    .MatchWholeWord = True
    .MatchWildcards = False
    .MatchSoundsLike = False
    .MatchAllWordForms = False
    Do While .Execute
    ccny = ccny + 1
    WD.Selection.Font.Color = wdColorRed
    Loop
    End With

    The essential point is

    WD.Selection.Font.Color = wdColorRed

    instead of

    WD.Selection.Find.Font.Color = wdColorRed

    because the latter sets the color to search for!

  3. #3
    4 Star Lounger
    Join Date
    Feb 2008
    Location
    United Kingdom
    Posts
    490
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Found Word Font colour (MSACCESS 2003)

    Thank you Hans for the reply. I appologise for wrong posting, do I need to remove the original one? Regards

  4. #4
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Found Word Font colour (MSACCESS 2003)

    > do I need to remove the original one?

    No, that's not necessary. I moved your question from the Access forum to here.

  5. #5
    4 Star Lounger
    Join Date
    Feb 2008
    Location
    United Kingdom
    Posts
    490
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Found Word Font colour (MSACCESS 2003)

    Sorry Hans, but I still cannot seem to get my font to chenge color on the found word. The found word grows to size 18, but still is in black color. Amended code below. Thanks

    Next TY

    Me.List152.ListIndex = 0
    Me.List152 = Null

    Me.List208.Visible = True
    Me.Label209.Visible = True
    Me.List208.Requery

    DoEvents
    WD.ActiveDocument.Saved = True

  6. #6
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Found Word Font colour (MSACCESS 2003)

    This part of the code doesn't have to do anything with the font color.

    The line

    WD.ActiveDocument.Saved = True

    tells Word that the document has already been saved (even if that isn't actually true), so that it will not have to be saved when it's closed.

  7. #7
    4 Star Lounger
    Join Date
    Feb 2008
    Location
    United Kingdom
    Posts
    490
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Found Word Font colour (MSACCESS 2003)

    Sorry Hans, that was my fault. I thought I had pasted in more code than shown. Yes that statement was put in to avoid seeing the Do you want to save caption appearing. The code posted should have been.

    'Create an instance of MS Word
    Set WD = CreateObject(Class:="Word.Application")
    WD.Visible = True
    '
    ' 'Open the Document
    WD.Documents.Open Filename:=LWordDoc, ReadOnly:=True

    Me.List152.SetFocus
    Me.List152.ListIndex = 0

    For TY = 0 To Me.List152.ListCount - 1
    Me.List152.ListIndex = TY

    With WD.Selection.Find
    .ClearFormatting
    .Text = "When" ' Me.List152.Value
    .Replacement.ClearFormatting
    .Replacement.Text = ""
    .Forward = True
    .Wrap = wdFindContinue
    .Format = False
    .MatchCase = False
    .MatchWholeWord = True
    .MatchWildcards = False
    .MatchSoundsLike = False
    .MatchAllWordForms = False

    Do While WD.Selection.Find.Execute
    'Do While .Execute
    ccny = ccny + 1
    WD.Selection.Font.Color = wdColorRed
    WD.Selection.Font.Bold = True
    WD.Selection.Font.Size = 18
    Loop
    End With


    Next TY

    Me.List152.ListIndex = 0
    Me.List152 = Null

    Me.List208.Visible = True
    Me.Label209.Visible = True
    Me.List208.Requery

    DoEvents
    WD.ActiveDocument.Saved = True

    I have scrolled down the page this time to make sure its all here. Thanks

  8. #8
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Found Word Font colour (MSACCESS 2003)

    When I test the central part of the code (omitting all the stuff about list boxes etc. that I don't have), it does make the searched-for text red, bold and 18 points, so I don't know why it doesn't change the color in your document. <img src=/S/shrug.gif border=0 alt=shrug width=39 height=15>

  9. #9
    4 Star Lounger
    Join Date
    Feb 2008
    Location
    United Kingdom
    Posts
    490
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Found Word Font colour (MSACCESS 2003)

    Thanks Hans, its strange as I thought this code did work before. I thought the line making it read only might cause it but it doesn't. I have played with a macro after typing in a word in a color, and it works when run. So I cannot think what else it can be, at least with your help I know the syntax is okay, so I will think where to go next. Many thanks again.

  10. #10
    4 Star Lounger
    Join Date
    Feb 2008
    Location
    United Kingdom
    Posts
    490
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Found Word Font colour (MSACCESS 2003)

    Hans, at last I found the reason, I had lost my references to the Word library. Have put it back and alls well. Thanks again, regards

  11. #11
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Found Word Font colour (MSACCESS 2003)

    Thanks for sharing the solution.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •