PDA

View Full Version : select 2 pages



saban
01-24-2006, 03:08 AM
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

saban
01-24-2006, 03:14 AM
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


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

TonyJollans
01-24-2006, 03:19 AM
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 ..
Selection.Bookmarks("\Page").Select
will select the whole of the page the selection is on.

saban
01-24-2006, 07:39 AM
thnx

saban
01-24-2006, 07:41 AM
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

TonyJollans
01-24-2006, 07:45 AM
ActiveDocument.Close wdDoNotSaveChanges

saban
01-24-2006, 07:52 AM
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

TonyJollans
01-24-2006, 08:36 AM
Msgbox Selection.Information(wdActiveEndPageNumber)

should do it.

saban
01-25-2006, 09:05 AM
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

TonyJollans
01-25-2006, 01:11 PM
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 ...

Selection.Find.Execute
SaveStart = Selection.Start
SaveEnd = Selection.End
' Do your something
ActiveDocument.Range(SaveStart, SaveEnd).Select

fumei
01-26-2006, 09:34 AM
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.

saban
01-27-2006, 01:25 AM
thnx

I will give it a try