Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 8
Default Print UserForm w/ Borders

I have a userform that I would like to print ("Print" commandbutton on
userform). However, if I use the UserForm.PrintForm method, it doesn't print
the borders with the userform. Unfortunately, the title of the userform is
important in my application, so I would like to be able to print the userform
with the borders. I found a VB 4.0 API call that creates a picture object
(new to VB 4.0) to do this. I was hoping to find a VBA article that would do
the same. Does anybody know of anything that might help?

Thanks!
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default Print UserForm w/ Borders

Here is a way to do it using the Windows API: I believe it will do what you
want. (gets a picture of a userform and puts it on a sheet. Then prints
the sheet. )


Modification of code originally posted by
"Orlando Magalhães Filho"


Modified to capture just the userform (not the whole window).


In a General Module:


Declare Sub keybd_event Lib "user32" (ByVal bVk As Byte, _
ByVal bScan As Byte, ByVal dwFlags As Long, ByVal dwExtraInfo As Long)


'Public Const VK_SNAPSHOT = &H2C


Public Const VK_SNAPSHOT = 44
Public Const VK_LMENU = 164
Public Const KEYEVENTF_KEYUP = 2
Public Const KEYEVENTF_EXTENDEDKEY = 1


Sub Test()
UserForm1.Show
End Sub


In the userform module:


Private Sub CommandButton1_Click()
' keybd_event VK_SNAPSHOT, 0, 0, 0
DoEvents
keybd_event VK_LMENU, 0, KEYEVENTF_EXTENDEDKEY, 0 ' key down
keybd_event VK_SNAPSHOT, 0, KEYEVENTF_EXTENDEDKEY, 0
keybd_event VK_SNAPSHOT, 0, KEYEVENTF_EXTENDEDKEY + KEYEVENTF_KEYUP, 0
keybd_event VK_LMENU, 0, KEYEVENTF_EXTENDEDKEY + KEYEVENTF_KEYUP, 0
DoEvents
Workbooks.Add
Application.Wait Now + TimeValue("00:00:01")
ActiveSheet.PasteSpecial Format:="Bitmap", Link:=False,
DisplayAsIcon:=False
ActiveSheet.Range("A1").Select
ActiveWindow.SelectedSheets.PrintOut Copies:=1
ActiveWorkbook.Close False
End Sub

--
Regards,
Tom Ogilvy

"Maynard" wrote in message
...
I have a userform that I would like to print ("Print" commandbutton on
userform). However, if I use the UserForm.PrintForm method, it doesn't

print
the borders with the userform. Unfortunately, the title of the userform

is
important in my application, so I would like to be able to print the

userform
with the borders. I found a VB 4.0 API call that creates a picture object
(new to VB 4.0) to do this. I was hoping to find a VBA article that would

do
the same. Does anybody know of anything that might help?

Thanks!



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 8
Default Print UserForm w/ Borders

Perfect! Thanks for the quick response.

"Tom Ogilvy" wrote:

Here is a way to do it using the Windows API: I believe it will do what you
want. (gets a picture of a userform and puts it on a sheet. Then prints
the sheet. )


Modification of code originally posted by
"Orlando Magalhães Filho"


Modified to capture just the userform (not the whole window).


In a General Module:


Declare Sub keybd_event Lib "user32" (ByVal bVk As Byte, _
ByVal bScan As Byte, ByVal dwFlags As Long, ByVal dwExtraInfo As Long)


'Public Const VK_SNAPSHOT = &H2C


Public Const VK_SNAPSHOT = 44
Public Const VK_LMENU = 164
Public Const KEYEVENTF_KEYUP = 2
Public Const KEYEVENTF_EXTENDEDKEY = 1


Sub Test()
UserForm1.Show
End Sub


In the userform module:


Private Sub CommandButton1_Click()
' keybd_event VK_SNAPSHOT, 0, 0, 0
DoEvents
keybd_event VK_LMENU, 0, KEYEVENTF_EXTENDEDKEY, 0 ' key down
keybd_event VK_SNAPSHOT, 0, KEYEVENTF_EXTENDEDKEY, 0
keybd_event VK_SNAPSHOT, 0, KEYEVENTF_EXTENDEDKEY + KEYEVENTF_KEYUP, 0
keybd_event VK_LMENU, 0, KEYEVENTF_EXTENDEDKEY + KEYEVENTF_KEYUP, 0
DoEvents
Workbooks.Add
Application.Wait Now + TimeValue("00:00:01")
ActiveSheet.PasteSpecial Format:="Bitmap", Link:=False,
DisplayAsIcon:=False
ActiveSheet.Range("A1").Select
ActiveWindow.SelectedSheets.PrintOut Copies:=1
ActiveWorkbook.Close False
End Sub

--
Regards,
Tom Ogilvy

"Maynard" wrote in message
...
I have a userform that I would like to print ("Print" commandbutton on
userform). However, if I use the UserForm.PrintForm method, it doesn't

print
the borders with the userform. Unfortunately, the title of the userform

is
important in my application, so I would like to be able to print the

userform
with the borders. I found a VB 4.0 API call that creates a picture object
(new to VB 4.0) to do this. I was hoping to find a VBA article that would

do
the same. Does anybody know of anything that might help?

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
Cell borders do not print on one side of print area?? alan82 Excel Discussion (Misc queries) 4 May 3rd 23 07:42 PM
borders don't appear in print preview? Claire Excel Discussion (Misc queries) 4 April 3rd 23 01:11 PM
cell borders that I create dont show on print preview or print scott3435 Excel Discussion (Misc queries) 2 April 6th 06 02:37 AM
Print without borders Anthony Excel Discussion (Misc queries) 4 September 12th 05 09:27 PM
Can't print diagonal borders although they show on print preview Excel-lover Excel Discussion (Misc queries) 7 August 30th 05 01:28 AM


All times are GMT +1. The time now is 06:52 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"