code required

K

kalyan

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
 
H

Helmut Weber

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
 
K

kalyan

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

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
 
K

kalyan

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


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-
 
H

Helmut Weber

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
 
K

kalyan

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
 
H

Helmut Weber

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
 
F

fumei via OfficeKB.com

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.
 
K

kalyan

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??
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top