Results 1 to 3 of 3
  1. #1
    3 Star Lounger
    Join Date
    Jan 2001
    Location
    Wellington, Wellington, New Zealand
    Posts
    378
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Set range equal to field (any version?)

    Hi

    [Oops. I seem to be getting variable results. I've now had the insert the blue line to make it work.]

    I'm sure the following technique is in WOPR somewhere, but I couldn't find it. So, just in case it's not ...

    You're looping through the fields in a document.

  2. #2
    Super Moderator
    Join Date
    May 2002
    Location
    Canberra, Australian Capital Territory, Australia
    Posts
    3,896
    Thanks
    0
    Thanked 188 Times in 172 Posts

    Re: Set range equal to field (any version?)

    Hi Dale,

    Depending on what you're doing, you may not even need to define the range. For example, the following does the same as your code (I think):

    Private Sub HtmlEquivalentDocsToHtml()
    Dim MyField As Field
    For Each MyField In ActiveDocument.Fields
    If MyField.Type = wdFieldHyperlink Then
    If LCase$(MyField.Code.Style) = "hyperlink to html-equivalent doc" Then
    Replace LCase$(MyField.Code), ".doc", ".html"
    End If
    End If
    Next MyField
    End Sub

    Cheers
    Cheers,

    Paul Edstein
    [MS MVP - Word]

  3. #3
    3 Star Lounger
    Join Date
    Jan 2001
    Location
    Wellington, Wellington, New Zealand
    Posts
    378
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Re: Set range equal to field (any version?)

    1. Ah, another subtlety. "MyField.Code.Style" returns the paragraph style, whereas my two lines of codes (set and modify MyRange) define a range that returns the character style (which, in the example I gave, is what I wanted).

    2. I must confess I had all sorts of problems finding a range definition that returned the character style (rather than the underlying paragraph style). If I'm right, the key is to have an end point of "End-1" or "End-2" (or more), although presumably the end point has to be within the hyperlink. Having said that, I get variable results. I think it's to do with how the character style has been applied. But "End-1" seems to consistently return a range that gives me the character style.

    3. I noticed your "Replace" statement. Word 97 doesn't recognise it, so presumably it was added later. So much easier!

    Thanks for your help
    Dale

Posting Permissions

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