Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
DiscussionsAccessExcelInfoPathOutlookPowerPointPublisherWord
DirectoryUser Groups
Related Topics
Outlook ExpressInternet ExplorerWindowsMS Server ProductsMore Topics ...

MS Office Forum / Word / Programming / November 2007

Tip: Looking for answers? Try searching our database.

code required

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
kalyan - 20 Nov 2007 12:51 GMT
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
Helmut Weber - 20 Nov 2007 21:25 GMT
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
kalyan - 22 Nov 2007 06:41 GMT
> Hi Kalyan,
>
[quoted text clipped - 20 lines]
>
> 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
kalyan - 22 Nov 2007 09:53 GMT
> > Hi Kalyan,
>
[quoted text clipped - 32 lines]
>
> - 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-
Helmut Weber - 22 Nov 2007 16:16 GMT
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
kalyan - 27 Nov 2007 14:18 GMT
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

> Hi Kalyan,
>
[quoted text clipped - 54 lines]
>
> Vista Small Business, Office XP
Helmut Weber - 27 Nov 2007 15:35 GMT
Hi Kalyan,

>input
>-----------
[quoted text clipped - 9 lines]
>*    [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
fumei - 27 Nov 2007 17:53 GMT
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.
kalyan - 29 Nov 2007 13:07 GMT
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??

> The code looks a little odd to me as well.
>
[quoted text clipped - 3 lines]
> --
> Message posted via OfficeKB.comhttp://www.officekb.com/Uwe/Forums.aspx/word-programming/200711/1

Rate this thread:






 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.