Re: List pages to print, select one page
- From: "Greg Maxey" <gmaxey@xxxxxxxxxxxxxxxxxxx>
- Date: Mon, 17 Dec 2007 09:36:45 -0500
Bruce,
You probably don't want to clutter you list of pages the user can select
from with any other bookmark name. One way to do this is with a UserForm.
Create a UserForm that contains a ListBox that list the pages the User can
choose from (I would make it a multi-select list) and a Command Button.
Populate the Listbox with the list of pages bookmarked "Page_1", Page_2",
etc.
Here is some sample code that you could use:
Private Sub CommandButton1_Click()
Dim i As Long
Dim pStr As String
If ListBox1.ListIndex <> -1 Then
For i = 0 To ListBox1.ListCount - 1
If ListBox1.Selected(i) Then
pStr = pStr + ListBox1.List(i) & ", "
End If
Next i
End If
'Clean up string
pStr = Left(pStr, Len(pStr) - 2)
'PrintOut
Application.PrintOut Range:=wdPrintRangeOfPages, Pages:=pStr
Unload Me
End Sub
Private Sub UserForm_Initialize()
Dim oBM As Bookmark
Dim oBMs As Bookmarks
Set oBMs = ActiveDocument.Bookmarks
For Each oBM In oBMs
If InStr(oBM.Name, "Page_") > 0 Then
Me.ListBox1.AddItem Mid(oBM.Name, 6, Len(oBM.Name) - 5)
End If
Next
End Sub
--
Greg Maxey/Word MVP
See:
http://gregmaxey.mvps.org/word_tips.htm
For some helpful tips using Word.
BruceM wrote:
I have a situation where the user may select one of several possible
pages to print. My idea (which may be off the mark, but it's what
has occurred to me) is that each of the pages would contain a
bookmark. I have adapted some code Jay Freedman posted about a year
ago to list bookmarks. I run the code as a macro.
Dim bkm As Word.Bookmark
Dim doc As Word.Document
Dim strBkm As String
Set doc = ActiveDocument
strBkm = ""
For Each bkm In doc.Bookmarks
strBkm = strBkm & bkm.Name & vbCrLf
Next
MsgBox strBkm
This produces a list of bookmarks in the document. I realize the
list as produced by this code is for display only, but what I hope is
that the user can select from the list, thereby printing the page on
which the bookmark appears. I already have worked out some code that
can identify the page number. Maybe it would be something like:
Dim b1 as Long
b1 = ActiveDocument.Bookmarks("MoreStart").Range _
.Information(wdActiveEndAdjustedPageNumber)
ActiveDocument.PrintOut _
Range:=wdPrintFromTo, From:=CStr(b1), To:=CStr(b1)
This may not be the smoothest way to accomplish what I need. For
instance, maybe I can produce a list of bookmarks, and when the user
selects one Word can go to that page, and I can use wdPrintSelection,
or something like that. Or maybe there is another option I have not
considered.
The main thing is that I would first need to have a user-selectable
list to identify the page that needs to be printed.
.
- Follow-Ups:
- Re: List pages to print, select one page
- From: BruceM
- Re: List pages to print, select one page
- References:
- List pages to print, select one page
- From: BruceM
- List pages to print, select one page
- Prev by Date: Page Background Problem in Word 2007
- Next by Date: Re: specifying word folder to save in from VB in access
- Previous by thread: List pages to print, select one page
- Next by thread: Re: List pages to print, select one page
- Index(es):
Loading