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 2006

Tip: Looking for answers? Try searching our database.

What macro command returns chapter and page number?

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Goody - 01 Nov 2006 21:55 GMT
I am writing a Word macro to list the pages in a document, and I need a
command loop that returns each page number in its printed format, e.g. 2-1.
Lüko Willms - 04 Nov 2006 08:31 GMT
Am Wed, 1 Nov 2006 20:55:02 UTC,  schrieb Goody
<Goody@discussions.microsoft.com>  auf
microsoft.public.word.vba.general :

> I am writing a Word macro to list the pages in a document, and I need a
> command loop that returns each page number in its printed format, e.g. 2-1.

 Why don't you simply create a table of contents in Word for your
document, or an index of items on the header or footers so that those
pagenumbers do automatically appear in that index?

 No special programming or macros needed for that.

Yours,
L.W.
Goody - 06 Nov 2006 16:54 GMT
The table that I am building is a revision list, with each page number listed
in a cell, and the revision letter of that page in the adjacent cell. Since
my first posting, I have developed a procedure that accomplishes what I was
trying to do, by placing a bookmark at the start of a page, then placing a
cross reference to the bookmark in the appropriate table cell. It gives me
the proper page number format, but it is not working as intended. When it
reaches the bottom of the table, it is supposed to return to the first blank
cell, which is row #2, two columns to the right. For some reason, the
InsertCrossReference method overwrites the data in the first column. The
InsertAfter command on the next line puts its argument in the proper cell. I
cannot determine why this is occurring. The code is shown below.

I would appreciate any suggestions you might have.

Goody
**************************
Sub PopulateRevList()
'
' Macro written 11/03/2006 by ray.dale
' It lists all of the pages in a document in the revision list table, along
with "-" for each page.
'
   Dim tblRevList As Table
   Dim columnstart As Integer, rowstart As Integer, irowcount As Integer,
icolcount As Integer
   Dim irow As Long, icolumn As Long
   Set tblRevList = ActiveDocument.Tables(2)
   icolumn = 1
   irow = 2
   irowcount = tblRevList.Rows.Count - 1
   icolcount = tblRevList.Columns.Count
   Selection.GoTo What:=wdGoToPage, Which:=wdGoToFirst, Count:=1, Name:=""
' Move cursor to start of document.
   
' Move through the document page by page
   For Each ipage In ActiveDocument.ActiveWindow.ActivePane.Pages
       With ActiveDocument.Bookmarks
           .Add Range:=Selection.Range, Name:="here"
           .DefaultSorting = wdSortByName
           .ShowHidden = False
       End With    ' Set bookmark for reference.
       Selection.GoTo What:=wdGoToTable, Which:=wdGoToFirst, Count:=2,
Name:=""
' Move to Page List table.
       MsgBox "The row number is " & irow & ", and the column number is " &
icolumn
       tblRevList.Cell(irow, icolumn).Range.InsertCrossReference
ReferenceType:=wdRefTypeBookmark, ReferenceKind:= _
           wdPageNumber, ReferenceItem:="here", InsertAsHyperlink:=False, _
           IncludePosition:=False, SeparateNumbers:=False,
SeparatorString:=" "
' Move to next page number cell and insert current page number of bookmark.

       tblRevList.Cell(irow, icolumn + 1).Range.InsertAfter "-"  ' Enter
hyphen in adjacent cell.
       Selection.GoTo What:=wdGoToBookmark, Name:="here"   ' Return to
bookmark location.

       ActiveDocument.Bookmarks("here").Delete ' Clear bookmark
       Application.Browser.Target = wdBrowsePage   ' Change to browse by page
       Application.Browser.Next    ' Move to top of next page
       If irow = irowcount + 1 Then    ' Is cell at the bottom of the table?
           icolumn = icolumn + 2   ' If so, move two columns to the right
           irow = 2                '  and back to the top of the table.
       Else
           irow = irow + 1         ' Otherwise, move to next row
       End If
   Next
   tblRevList.Range.Fields.Unlink   ' Unlink cross-reference fields in table.
   Selection.GoTo What:=wdGoToTable, Which:=wdGoToFirst, Count:=2, Name:=""
  ' Return to start of Revision List table
End Sub
**********************

> Am Wed, 1 Nov 2006 20:55:02 UTC,  schrieb Goody
> <Goody@discussions.microsoft.com>  auf
[quoted text clipped - 11 lines]
> Yours,
> L.W.
 
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.