Hi

Is there any way of reading and modifying word document page by page
in VBA....if so can anybody give me the piece of code


Awaiting for early response


Thanks & Regards
Kalyan

Re: code required by Helmut

Helmut
Wed Nov 21 13:21:38 PST 2007

Hi Kalyan,

Sub Test67()
Dim lCnt As Long
Dim lPages As Long
lPages = ActiveDocument.ComputeStatistics(wdStatisticPages)
For lCnt = 1 To lPages
Selection.GoTo _
what:=wdGoToPage, _
which:=wdGoToAbsolute, _
Count:=lCnt
Selection.Bookmarks("\page").Select
' beware of what you are doing to the selection
Next

End Sub

--

Gruß

Helmut Weber, MVP WordVBA

Vista Small Business, Office XP

Re: code required by kalyan

kalyan
Wed Nov 21 22:41:28 PST 2007

On Nov 22, 2:21 am, Helmut Weber <red....@t-online.de> wrote:
> Hi Kalyan,
>
> Sub Test67()
> Dim lCnt As Long
> Dim lPages As Long
> lPages =3D ActiveDocument.ComputeStatistics(wdStatisticPages)
> For lCnt =3D 1 To lPages
> Selection.GoTo _
> what:=3DwdGoToPage, _
> which:=3DwdGoToAbsolute, _
> Count:=3DlCnt
> Selection.Bookmarks("\page").Select
> ' beware of what you are doing to the selection
> Next
>
> End Sub
>
> --
>
> Gru=DF
>
> Helmut Weber, MVP WordVBA
>
> Vista Small Business, Office XP

Hi Helmut

Your code rocks!!!...so can we check for the existence of particular
text in page and if that exists can we replace a portion of text
between [ and ] or highlighted with a color in the same page....can i
have a piece of code for this type of action...

Thanks & Regards
Kalyan

Re: code required by kalyan

kalyan
Thu Nov 22 01:53:53 PST 2007

On Nov 22, 11:41 am, kalyan <kali...@gmail.com> wrote:
> On Nov 22, 2:21 am, Helmut Weber <red....@t-online.de> wrote:
>
>
>
>
>
> > Hi Kalyan,
>
> > Sub Test67()
> > Dim lCnt As Long
> > Dim lPages As Long
> > lPages =3D ActiveDocument.ComputeStatistics(wdStatisticPages)
> > For lCnt =3D 1 To lPages
> > Selection.GoTo _
> > what:=3DwdGoToPage, _
> > which:=3DwdGoToAbsolute, _
> > Count:=3DlCnt
> > Selection.Bookmarks("\page").Select
> > ' beware of what you are doing to the selection
> > Next
>
> > End Sub
>
> > --
>
> > Gru=DF
>
> > Helmut Weber, MVP WordVBA
>
> > Vista Small Business, Office XP
>
> Hi Helmut
>
> Your code rocks!!!...so can we check for the existence of particular
> text in page and if that exists can we replace a portion of text
> between [ and ] or highlighted with a color in the same page....can i
> have a piece of code for this type of action...
>
> Thanks & Regards
> Kalyan- Hide quoted text -
>
> - Show quoted text -

Also....
can i list out the bulleted text in the word document thru VBA
can i remove a bulleted text in a page thru VBA
can i add a bulleted text thru VBA

Thanks & Regards
Kalyan-


Re: code required by Helmut

Helmut
Thu Nov 22 08:16:47 PST 2007

Hi Kalyan,

yes and no, it all depends.
Sorry, these are too many questions for me right now.

So a bit of theory might help you more than just some code lines.

Whith the code I posted you get a page,
in a very simplified way.
Word doesn't really know much about pages.
Pages are recalculated on the fly,
depending on the printer and other variables.
If you do something to a page,
like deleting the last word,
the first Word from the next page
might move to the actual page.

Ok, if it has to be,
this replaces all text in brackets
on page 25, as it was when the macro started,
with some other text.

But note, that text in brackets may move from the
next page to the actual page and
complicate things a lot.

Split it all up in seperate questions and ask again.
Some other people might know as well,
and some might even know better.

Sub Test67()
Dim lPages As Long
Dim rTmp As Range
lPages = ActiveDocument.ComputeStatistics(wdStatisticPages)
ActiveDocument.Range(0, 0).Select
Selection.ExtendMode = False
Selection.GoTo _
what:=wdGoToPage, _
which:=wdGoToAbsolute, _
Count:=25
Set rTmp = Selection.Bookmarks("\page").Range
With rTmp.Find
.Text = "\[*\]" ' any text between brackets
.Replacement.Text = "[this was deleted]"
.Wrap = wdFindStop
.MatchWildcards = True
.Execute Replace:=wdReplaceAll
End With
Selection.Collapse
End Sub


--

Greetings from Bavaria, Germany

Helmut Weber, MVP WordVBA

Vista Small Business, Office XP

Re: code required by kalyan

kalyan
Tue Nov 27 06:18:13 PST 2007

am using the following code to remove bulleted text

Dim rngTarget As Word.Range
Dim oPara As Word.Paragraph
Set rngTarget = Selection.Range
With rngTarget
Call .Collapse(wdCollapseEnd)
.End = ActiveDocument.Range.End
For Each oPara In .Paragraphs
If oPara.Range.ListFormat.ListType = WdListType.wdListBullet
Then
oPara.Range.Select
Selection.Delete Unit:=wdCharacter, Count:=1
End If
Next
End With

this code works as follows

input
-----------
* Diagnostic hearing exams.
* [Routine Hearing tests]
* [Fitting and evaluation for hearing aids]
* [Hearing aids]

output
-----------
* Diagnostic hearing exams.
* [Routine Hearing tests]
* [Fitting and evaluation for hearing aids]
*

the problem occurs only if the bulleted text is the last one in the
list

any ideas to how to modify the code so that..even the last bullet
along with the text is removed

Thanks & Regards
Kalyan




On Nov 22, 9:16 pm, Helmut Weber <red....@t-online.de> wrote:
> Hi Kalyan,
>
> yes and no, it all depends.
> Sorry, these are too many questions for me right now.
>
> So a bit of theory might help you more than just some code lines.
>
> Whith the code I posted you get a page,
> in a very simplified way.
> Word doesn't really know much about pages.
> Pages are recalculated on the fly,
> depending on the printer and other variables.
> If you do something to a page,
> like deleting the last word,
> the first Word from the next page
> might move to the actual page.
>
> Ok, if it has to be,
> this replaces all text in brackets
> on page 25, as it was when the macro started,
> with some other text.
>
> But note, that text in brackets may move from the
> next page to the actual page and
> complicate things a lot.
>
> Split it all up in seperate questions and ask again.
> Some other people might know as well,
> and some might even know better.
>
> Sub Test67()
> Dim lPages As Long
> Dim rTmp As Range
> lPages = ActiveDocument.ComputeStatistics(wdStatisticPages)
> ActiveDocument.Range(0, 0).Select
> Selection.ExtendMode = False
> Selection.GoTo _
> what:=wdGoToPage, _
> which:=wdGoToAbsolute, _
> Count:=25
> Set rTmp = Selection.Bookmarks("\page").Range
> With rTmp.Find
> .Text = "\[*\]" ' any text between brackets
> .Replacement.Text = "[this was deleted]"
> .Wrap = wdFindStop
> .MatchWildcards = True
> .Execute Replace:=wdReplaceAll
> End With
> Selection.Collapse
> End Sub
>
> --
>
> Greetings from Bavaria, Germany
>
> Helmut Weber, MVP WordVBA
>
> Vista Small Business, Office XP


Re: code required by Helmut

Helmut
Tue Nov 27 07:35:57 PST 2007

Hi Kalyan,

>input
>-----------
>* Diagnostic hearing exams.
>* [Routine Hearing tests]
>* [Fitting and evaluation for hearing aids]
>* [Hearing aids]
>
>output
>-----------
>* Diagnostic hearing exams.
>* [Routine Hearing tests]
>* [Fitting and evaluation for hearing aids]
>*

I can't reproduce the behaviour you've described.
Though your code looks a bit odd to me,
but of course everybody is used to his own style,
it is working perfectly, it seems.

Sorry.

--

Greetings from Bavaria, Germany

Helmut Weber, MVP WordVBA

Vista Small Business, Office XP

Re: code required by fumei

fumei
Tue Nov 27 09:53:23 PST 2007

The code looks a little odd to me as well.

The last paragraph is bulleted because the code removes the text, but does
not change the style. Change the style.

--
Message posted via OfficeKB.com
http://www.officekb.com/Uwe/Forums.aspx/word-programming/200711/1


Re: code required by kalyan

kalyan
Thu Nov 29 05:07:41 PST 2007

Actually if i modify my code as follows

Dim rngTarget As Word.Range
Dim oPara As Word.Paragraph
Set rngTarget = Selection.Range
With rngTarget
Call .Collapse(wdCollapseEnd)
.End = ActiveDocument.Range.End
For Each oPara In .Paragraphs
If oPara.Range.ListFormat.ListType = WdListType.wdListBullet
Then
If oPara.Range.Text="Hearing aids" then
oPara.Range.Select
Selection.Delete Unit:=wdCharacter, Count:=1
End if
End If
Next
End With

then i get the output as follows

output
-----------
* Diagnostic hearing exams.
* [Routine Hearing tests]
* [Fitting and evaluation for hearing aids]
*

now how 2 handle this case??

On Nov 27, 10:53 pm, "fumei via OfficeKB.com" <u37563@uwe> wrote:
> The code looks a little odd to me as well.
>
> The last paragraph is bulleted because the code removes the text, but does
> not change the style. Change the style.
>
> --
> Message posted via OfficeKB.comhttp://www.officekb.com/Uwe/Forums.aspx/word-programming/200711/1