Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 10
Default number of copies in a print dialog box

Hi,

I am using vba to display the built in Print Dialog box, but i would like to
somehow store the number of copies that one chooses into a variable. So if
one chooses 10 as the number of copies to print, i want to be able to store
10 somewhere in my code. Can anyone help me with this?

Thanks
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 129
Default number of copies in a print dialog box

Hi,

the number of copies put in the Print dialog box doesn't seem to be
stored. (the number in the printer properties ("options" in the Page
Setup dialog) seems to be stored in each sheet)

I wrote some code for excel 2000. but I don't know a good way.
creating a custom userform to print may be more certain.


Public Const WH_CBT = 5
Public Const HCBT_DESTROYWND = 4
Public Const GWL_HINSTANCE = -6

Declare Function SetWindowsHookEx Lib "user32" _
Alias "SetWindowsHookExA" ( _
ByVal idHook As Long, ByVal lpfn As Long, _
ByVal hMod As Long, ByVal dwThreadId As Long) As Long
Declare Function UnhookWindowsHookEx Lib "user32" ( _
ByVal hHook As Long) As Long
Declare Function CallNextHookEx Lib "user32" ( _
hHook As Long, nCode As Long, _
wParam As Long, lParam As Long) As Long
Declare Function FindWindowEx Lib "user32" Alias "FindWindowExA" ( _
ByVal hwndParent As Long, ByVal hwndChildAfter As Long, _
ByVal lpszClass As String, ByVal lpszWindow As String) As Long
Declare Function GetCurrentThreadId Lib "kernel32" () As Long
Declare Function GetWindowLong Lib "user32" Alias "GetWindowLongA" ( _
ByVal hwd As Long, ByVal nIndex As Long) As Long
Declare Function GetWindowText Lib "user32" Alias "GetWindowTextA" ( _
ByVal hwnd As Long, ByVal lpString As String, ByVal cch As Long) As Long

Private g_hHookProc As Long
Private g_nCopies As Long

Public Function CBTHookProc(ByVal nCode As Long, _
ByVal wParam As Long, ByVal lParam As Long) As Long
Dim hwnd As Long, Ret As Long
Dim buf As String

On Error Resume Next

If nCode = HCBT_DESTROYWND Then
buf = String(260, Chr(0))
Ret = GetWindowText(wParam, buf, Len(buf))
buf = Left(buf, InStr(1, buf, Chr(0), 0) - 1)
If buf = "Print" Then
hwnd = FindWindowEx(wParam, 0, "EDTBX", vbNullString)
hwnd = FindWindowEx(wParam, hwnd, "EDTBX", vbNullString)
hwnd = FindWindowEx(wParam, hwnd, "EDTBX", vbNullString)
If hwnd < 0 Then
buf = String(260, Chr(0))
Ret = GetWindowText(hwnd, buf, Len(buf))
buf = Left(buf, InStr(1, buf, Chr(0), 0) - 1)
If buf = "" Then
g_nCopies = 0
Else
g_nCopies = CLng(buf)
End If
End If
End If
End If
CBTHookProc = CallNextHookEx(g_hHookProc, nCode, wParam, lParam)
End Function


Sub Test_PrintDialog()
Dim hwnd As Long, hInstance As Long, ThreadId As Long
Dim Ret As Long
hwnd = FindWindowEx(0, 0, "XLMAIN", Application.Caption)
hInstance = GetWindowLong(hwnd, GWL_HINSTANCE)
ThreadId = GetCurrentThreadId()
g_hHookProc = SetWindowsHookEx(WH_CBT, AddressOf CBTHookProc, _
hInstance, ThreadId)
If g_hHookProc < 0 Then
g_nCopies = -1
Ret = 0
On Error Resume Next
Ret = Application.Dialogs(xlDialogPrint).Show()
On Error GoTo 0
UnhookWindowsHookEx g_hHookProc
MsgBox g_nCopies
End If
End Sub

--
HTH,

okaizawa


LHaro wrote:
Hi,

I am using vba to display the built in Print Dialog box, but i would like to
somehow store the number of copies that one chooses into a variable. So if
one chooses 10 as the number of copies to print, i want to be able to store
10 somewhere in my code. Can anyone help me with this?

Thanks

Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Number of copies to print keep defaulting to 12 copies why? Boski Excel Worksheet Functions 1 October 8th 09 05:33 PM
print number of copies Sunny Excel Discussion (Misc queries) 1 August 29th 06 05:00 PM
Print number of copies Tarique Excel Discussion (Misc queries) 2 April 24th 06 07:45 PM
I need to print many copies of a document, how can I number them? bronxbobc Excel Discussion (Misc queries) 0 February 6th 06 09:28 PM
print dialog box with 2 copies as default? Johan Excel Programming 1 June 10th 05 10:51 AM


All times are GMT +1. The time now is 06:59 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"