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 / July 2005

Tip: Looking for answers? Try searching our database.

Loop thru doc problem

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
jbc - 20 Jul 2005 23:27 GMT
Hi,

The following code is working perfectly for me except when it hits a table.  
I would like it to SKIP tables and not put the sequential number field there.
I only want it if the paragraph style is Normal and not in a table.

Right now it is placing sequential numbers in each cell of the first table.  
I'm getting the following error message when it gets to the end of the first
row:

Run-time error 5251.  This is not a valid action for the end of a row.

I've tried several different options to get this to work.  I've been looking
at it all day and am still not getting anywhere.  

Any help would be greatly appreciated.

Thanks.

jbc
*********************************************
Dim oPar As Paragraph
Dim oRng As Range

ActiveWindow.View.ShowFieldCodes = True

For Each oPar In ActiveDocument.Paragraphs
 
  If oPar.Style = "Normal" Then
     If Not Mid(oPar.Range.Text, 3, 3) = "SEQ" Then
 
        oPar.Range.InsertBefore vbTab
        Set oRng = oPar.Range.Duplicate

        oRng.Collapse direction:=wdCollapseStart
        ActiveDocument.Fields.Add Range:=oRng, Type:=wdFieldSequence,
Text:= _
           "Paragraph \# ""[0000]"" \n "

        oRng.Paragraphs(1).Range.Fields(1).Result.Font.Bold = True
     
     End If
  End If

Next oPar

ActiveWindow.View.ShowFieldCodes = False
ActiveDocument.Fields.Update
*************************************************
Jay Freedman - 21 Jul 2005 03:01 GMT
Replace the line

   If oPar.Style = "Normal" Then

with

  If (oPar.Style = "Normal") And _
     (Not oPar.Range.Information(wdWithInTable)) Then

--
Regards,
Jay Freedman
Microsoft Word MVP         FAQ: http://word.mvps.org

>Hi,
>
[quoted text clipped - 45 lines]
>ActiveDocument.Fields.Update
>*************************************************
jbc - 21 Jul 2005 13:12 GMT
Jay,

Thank you so much.  I tried something very similar, but did not use the ( ).
Why do you need them?

Thanks.

jbc

> Replace the line
>
[quoted text clipped - 59 lines]
> >ActiveDocument.Fields.Update
> >*************************************************
Jay Freedman - 21 Jul 2005 17:48 GMT
The VBA interpreter doesn't "need" the parentheses that separate the
arguments of the And operator unless the standard order of operator
evaluation would be different from the intended logic -- which it isn't, in
this case. But I need them to remind me of how to read the statement (slow
meatware!).

The parentheses around wdWithInTable are necessary because I want to use the
result of the Information function -- see
http://word.mvps.org/FAQs/MacrosVBA/BracketsWithArgmnts.htm.

Signature

Regards,
Jay Freedman
Microsoft Word MVP          FAQ: http://word.mvps.org

> Jay,
>
[quoted text clipped - 70 lines]
>>> ActiveDocument.Fields.Update
>>> *************************************************

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.