Results 1 to 4 of 4
  1. #1
    Star Lounger
    Join Date
    Jan 2003
    Location
    San Francisco, California, USA
    Posts
    88
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Exclamation DoClick method for wdFieldRef type?

    Hello All,

    I'm trying to use the doclick method for a wdFieldRef type. What this macro should do is grab the ActiveEndPageNumber if the field is a wdFieldRef. If so, use doClick and then grab the ActiveEndPageNumber(after insertion point moves). If the destination page and the page number of the field don't match, then turn the link brown.

    This is what I have thus far:

    Sub XREFsToBlue()
    Dim oField As Field
    Dim objDoc As Document
    Dim oRange As Range
    Dim Sel As Selection
    Dim i As Integer
    Dim a As Integer
    Dim fldTemp


    Set objDoc = ActiveDocument

    For Each oField In objDoc.Fields
    If oField.Type = wdFieldRef Then
    oField.Select
    a = Selection.Information(wdActiveEndPageNumber)
    With Application
    .ScreenUpdating = True
    .ScreenRefresh
    End With
    oField.DoClick
    Application.ScreenRefresh
    i = Selection.Information(wdActiveEndPageNumber)
    If i <> a Then
    oField.Select
    Selection.Font.Color = wdColorBrown
    End If
    End If
    Next


    Set objDoc = Nothing

    End Sub
    Attached Files Attached Files

  2. #2
    Super Moderator
    Join Date
    Jan 2001
    Location
    Melbourne, Victoria, Australia
    Posts
    3,514
    Thanks
    3
    Thanked 143 Times in 136 Posts
    Can we do this without the selection object and following clicks around? This method applies character styles instead of brownifying the text directly.
    Code:
    Sub XREFsToBlue()
      Dim oField As Field, objDoc As Document
      Dim i As Integer, a As Integer
      Dim sRef() As String
      
      Set objDoc = ActiveDocument
      
      For Each oField In objDoc.Fields
        If oField.Type = wdFieldRef Then
          a = oField.Result.Information(wdActiveEndPageNumber)
          sRef = Split(Trim(oField.Code), " ")
          Debug.Print sRef(1)
          i = objDoc.Bookmarks(sRef(1)).Range.Information(wdActiveEndPageNumber)
          If i <> a Then
            oField.Result.Style = "Emphasis"
          Else
            oField.Result.Style = "Hyperlink"
          End If
        End If
      Next
      
      Set objDoc = Nothing
    
    End Sub
    Andrew Lockton, Chrysalis Design, Melbourne Australia

  3. #3
    Star Lounger
    Join Date
    Jan 2003
    Location
    San Francisco, California, USA
    Posts
    88
    Thanks
    1
    Thanked 0 Times in 0 Posts
    Hi Andrew, sorry for the late reply. My notifications are not on. This works great! I did not think of using character styles.

Posting Permissions

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