Consulting

Results 1 to 12 of 12

Thread: select 2 pages

  1. #1
    VBAX Mentor
    Joined
    Jan 2006
    Posts
    348
    Location

    select 2 pages

    how to select 2 pages (from large document), copy them to another document do something there and then close this document without saving and copy another instance of 2 pages and do something there and so on till end of the document

    Because at each of these 2 pages from large document I would count the xml tags to see on which pages they do not match

  2. #2
    VBAX Mentor
    Joined
    Jan 2006
    Posts
    348
    Location
    or better do be done with this code:
    which selects text between start and end tag: and now I would like this selected text to be copied into new document count the codes there( already have a count macro ) and tell me which page of large document this text was taken from

    [VBA]
    Sub SearchAndReplace()
    fkt_Search "<|", "|>", False
    End Sub
    Function fkt_Search(strStart As String, strEnd As String, bDelete As Boolean)
    Dim rng As Range
    Dim rngText As Range


    ' Range festlegen
    Set rng = ActiveDocument.Range

    strStart = "<Amend>"
    strEnd = "</Amend>"

    ' Range festlegen
    Set rngText = ActiveDocument.Range(0, 0)

    rngText.Collapse wdCollapseStart

    ' Such-Schleife
    With rng.Find
    .Format = False
    .Text = strStart

    ' Suche nach Start-Tag
    .Execute

    Do While .Found = True
    ' Fundstelle mit Start-Tag anlegen
    rngText.SetRange rng.Start, rng.End

    ' Suchtextbereich reduzieren
    rng.SetRange rng.End, ActiveDocument.Range.End

    ' Suche nach End-Tag
    .Execute FindText:=strEnd, Forward:=True

    ' Abbruch wenn kein End-Tag
    If .Found = False Then Exit Function

    ' Fundstelle bis End-Tag erweitern
    rngText.SetRange rngText.Start, rng.End

    If bDelete = False Then
    ' fablich hervorheben
    rngText.Select
    rngText.Font.Color = wdColorAqua

    Else
    ' l?schen
    rngText.Delete
    End If

    ' Suchtextbereich zur Endposition reduzieren
    rng.Collapse wdCollapseEnd

    ' Start-Tag suchen
    .Execute FindText:=strStart, Forward:=True
    Loop

    rng.Collapse wdCollapseEnd
    End With
    End Function
    [/VBA]
    Last edited by geekgirlau; 01-26-2006 at 05:23 PM. Reason: Put code in VBA tags

  3. #3
    VBAX Master TonyJollans's Avatar
    Joined
    May 2004
    Location
    Norfolk, England
    Posts
    2,291
    Location
    Hi saban,

    I'm not entirely sure what you're trying to do but it may help you to know that there is a built-in bookmark which you can use to get a page from a document ..
    [vba]Selection.Bookmarks("\Page").Select[/vba]
    will select the whole of the page the selection is on.
    Enjoy,
    Tony

    ---------------------------------------------------------------
    Give a man a fish and he'll eat for a day.
    Teach him how to fish and he'll sit in a boat and drink beer all day.

    I'm (slowly) building my own site: www.WordArticles.com

  4. #4
    VBAX Mentor
    Joined
    Jan 2006
    Posts
    348
    Location
    thnx

  5. #5
    VBAX Mentor
    Joined
    Jan 2006
    Posts
    348
    Location
    one more q:
    ActiveDocument.Close -gives you active document to close but how can I avoid to get this annoying message "would you like to save it (Yes, No , Cancel)" -and i dont want to save it

  6. #6
    VBAX Master TonyJollans's Avatar
    Joined
    May 2004
    Location
    Norfolk, England
    Posts
    2,291
    Location
    ActiveDocument.Close wdDoNotSaveChanges
    Enjoy,
    Tony

    ---------------------------------------------------------------
    Give a man a fish and he'll eat for a day.
    Teach him how to fish and he'll sit in a boat and drink beer all day.

    I'm (slowly) building my own site: www.WordArticles.com

  7. #7
    VBAX Mentor
    Joined
    Jan 2006
    Posts
    348
    Location
    Actualy when text is selected between tho tag <amend> and </amend> I would like to get msgbox showing me on which page this text was selected

  8. #8
    VBAX Master TonyJollans's Avatar
    Joined
    May 2004
    Location
    Norfolk, England
    Posts
    2,291
    Location
    Msgbox Selection.Information(wdActiveEndPageNumber)

    should do it.
    Enjoy,
    Tony

    ---------------------------------------------------------------
    Give a man a fish and he'll eat for a day.
    Teach him how to fish and he'll sit in a boat and drink beer all day.

    I'm (slowly) building my own site: www.WordArticles.com

  9. #9
    VBAX Mentor
    Joined
    Jan 2006
    Posts
    348
    Location
    just one question

    when I loop throgh text looking for </Amend> when it is found i 'do something
    then i search further. But how can I find this same </Amend> one more time
    (Not to find another instance of </Amend> but the same as previous and after i have found it 2 times i move to the next instance

    Thnx

  10. #10
    VBAX Master TonyJollans's Avatar
    Joined
    May 2004
    Location
    Norfolk, England
    Posts
    2,291
    Location
    That depends what the something you do is! If you change the Selection (assuming you are using Selection.Find) then what you have to do depends on what you change it to. And if you aren't changing the Selection there's no need to Find it again.

    You could, however, try something like ...

    [vba]Selection.Find.Execute
    SaveStart = Selection.Start
    SaveEnd = Selection.End
    ' Do your something
    ActiveDocument.Range(SaveStart, SaveEnd).Select[/vba]
    Enjoy,
    Tony

    ---------------------------------------------------------------
    Give a man a fish and he'll eat for a day.
    Teach him how to fish and he'll sit in a boat and drink beer all day.

    I'm (slowly) building my own site: www.WordArticles.com

  11. #11
    VBAX Wizard
    Joined
    May 2004
    Posts
    6,713
    Location
    This is alll tied up with your othee thread.

    One other way is when you find the first instance, make a bookmark of it. So assuming you are using Selection.Find, when .Execute finds it, it is selected. You can then make atemporary bookmark of that. Then whenever you want to get it again, you can call the bookmark.

    Just be sure - if you are still in the .Find loop - that if you use this you also mark where you were before, so you can continue on with the loop.

  12. #12
    VBAX Mentor
    Joined
    Jan 2006
    Posts
    348
    Location
    thnx

    I will give it a try

Posting Permissions

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