Results 1 to 9 of 9
  1. #1
    Bronze Lounger
    Join Date
    Jan 2001
    Location
    Melbourne, Australia
    Posts
    1,294
    Thanks
    0
    Thanked 0 Times in 0 Posts

    working with ranges (WordXP)

    how do I set a range to a string & then go to that range so I can format which is within an existing defined range?

    eg.
    range1 start
    rangeNew = some text
    range1 end

    goto the newrange & format

    can this be done or should I just do a find within my range1

    many thanks Diana

  2. Subscribe to our Windows Secrets Newsletter - It's Free!

    Get our unique weekly Newsletter with tips and techniques, how to's and critical updates on Windows 7, Windows 8, Windows XP, Firefox, Internet Explorer, Google, etc. Join our 480,000 subscribers!

    Excel 2013: The Missing Manual

    + Get this BONUS — free!

    Get the most of Excel! Learn about new features, basics of creating a new spreadsheet and using the infamous Ribbon in the first chapter of Excel 2013: The Missing Manual - Subscribe and download Chapter 1 for free!

  3. #2
    Super Moderator jscher2000's Avatar
    Join Date
    Feb 2001
    Location
    Silicon Valley, USA
    Posts
    23,112
    Thanks
    5
    Thanked 93 Times in 89 Posts

    Re: working with ranges (WordXP)

    Not exactly sure what you're trying to do. You can set a range to any known position in the document (such as the selection, characters 21 through 30, table 6, etc.). If you want to set a range to a known string of characters in an unknown location in the document, then Find sounds like the best way, since otherwise you don't have any way to get the coordinates of the string. Make sense?

  4. #3
    5 Star Lounger
    Join Date
    May 2001
    Location
    Stuttgart, Baden-W, Germany
    Posts
    931
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: working with ranges (WordXP)

    I'm not sure what you are trying to do, either. But it looks from your pseudo code like you are inserting some text.

    If your Range was empty (range1.Start=range1.End), and you use
    range1.InsertAfter "Some text"
    range1 will now encompass "Some text", and you can format it any way you want:
    range1.Style = "Default Paragraph Font"
    range1.Font.Bold = True

    <img src=/S/cheers.gif border=0 alt=cheers width=30 height=16> Klaus

  5. #4
    Bronze Lounger
    Join Date
    Jan 2001
    Location
    Melbourne, Australia
    Posts
    1,294
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: working with ranges (WordXP)

    hi
    this is my code & what I'm wanting to achieve:

    Set rngThisHeader = sectionThis.Headers(wdHeaderFooterPrimary).Range
    rngThisHeader.SetRange rngThisHeader.Start, rngThisHeader.Start
    rngThisHeader.InsertBefore sAutoTextName
    'set a range to the autotext name string so i can select the autotext string then
    rngThisHeader.InsertAutoText

    currently the code works in page layout view & is formatting in the header however if I use the Selection property, then Words view & window is changed to display the header pane either at the top or bottom of the screen.(which i dont want).
    I would like to set a range to my autotext string so I can select the string & then insert the autotext.
    i thought there may be a way to do this?
    or should I just redefine my range which would include the string & then do a find for the string in my range?

    Diana

  6. #5
    Plutonium Lounger
    Join Date
    Nov 2001
    Posts
    10,550
    Thanks
    0
    Thanked 7 Times in 7 Posts

    Re: working with ranges (WordXP)

    If I have understood you correctly then the easiest thing to do will be to replace
    <font face="Georgia">rngThisHeader.InsertBefore sAutoTextName</font face=georgia>
    with
    <font face="Georgia">ActiveDocument.AttachedTemplate.Aut oTextEntries(sAutoTextName).Insert Where:=rngThisHeader, RichText:=True</font face=georgia>

    This will insert the Autotext entry, instead of inserting the name of the autotext and then trying to select it and insert the entry from there.

    StuartR

  7. #6
    Bronze Lounger
    Join Date
    Jan 2001
    Location
    Melbourne, Australia
    Posts
    1,294
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: working with ranges (WordXP)

    Hi Stewart
    I used the find in a range. this is my working code:

    'Insert in header
    Set rngThis = sectionThis.Headers(wdHeaderFooterFirstPage).Range
    rngThis.SetRange rngThis.Start, rngThis.Start
    rngThis.InsertBefore sAutoTextName
    Set rngThis = sectionThis.Headers(wdHeaderFooterFirstPage).Range
    rngThis.SetRange rngThis.Start, rngThis.Start
    rngThis.Find.Execute FindText:=sAutoTextName, Forward:=True
    If rngThis.Find.Found = True Then rngThis.InsertAutoText

    Diana

  8. #7
    Plutonium Lounger
    Join Date
    Nov 2001
    Posts
    10,550
    Thanks
    0
    Thanked 7 Times in 7 Posts

    Re: working with ranges (WordXP)

    It seems a very complicaetd way to insert AutoText to me, but if it works and your happy with it then I guess that's what matters.

    StuartR

  9. #8
    Bronze Lounger
    Join Date
    Jan 2001
    Location
    Melbourne, Australia
    Posts
    1,294
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: working with ranges (WordXP)

    Hi Stewart

    Yeah I thought it may have been a bit complicated thats why I posted, to find out if there was easier code to handle inserting autotext entry.someone must have done it alot easier. oh well

    cheers Diana

  10. #9
    Super Moderator jscher2000's Avatar
    Join Date
    Feb 2001
    Location
    Silicon Valley, USA
    Posts
    23,112
    Thanks
    5
    Thanked 93 Times in 89 Posts

    Re: working with ranges (WordXP)

    This code seems to insert a string into a header, then search for that string in the same header, then insert AutoText (replacing the string?). That does seem to have two extra steps in it. <img src=/S/smile.gif border=0 alt=smile width=15 height=15> Maybe this would be easier?

    <pre>Sub TestInserter()
    InsertATInHeader "thx", wdHeaderFooterFirstPage
    End Sub

    Sub InsertATInHeader(strATname As String, Optional intHeader As WdHeaderFooterIndex = _
    wdHeaderFooterPrimary)
    ' Insert specified autotext into the specified header in the "current" section
    Dim rngHdr As Range
    Set rngHdr = ActiveDocument.Sections(Selection.Information(wdAc tiveEndSectionNumber)). _
    Headers(intHeader).Range
    rngHdr.Collapse direction:=wdCollapseStart
    NormalTemplate.AutoTextEntries(strATname).Insert Where:=rngHdr, RichText:=True
    Set rngHdr = Nothing
    End Sub</pre>

    Not shorter, obviously. <img src=/S/laugh.gif border=0 alt=laugh width=15 height=15>

Posting Permissions

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