View Full Version : Print UserForm with a Webbrower Control
gsouza
02-17-2005, 11:53 AM
Hi everybody again,  Hope someone can help.  I have a userform with a webbrowser control.  The control is linked and views to webpages, word files, etc.  How can I print all pages in the content of what is seen in the webbowser control even though it is not fully viewed on the screen.  For instance I open up a Word Document in the control, I can only view one page at a time.  I want to print out all the pages and only the pages of the document, not the userform itself.  I want to print out all the content of the word document and only the word document.  Hope someone has this answer.
gsouza
02-18-2005, 04:51 AM
Does anybody understand what I mean or is there no way to do it?
Killian
02-18-2005, 05:44 AM
I assume your UserForm is in Word already.
You'll just need to assign the link's path property to a variable and use it in something like this:
Sub PrintLink()
Dim myDoc As Document
Dim myDocPath As String
    myDocPath=<link path property>
    
    Set myDoc = Documents.Open(myDocPath)
    myDoc.PrintOut Range:=wdPrintAllDocument
    myDoc.Close SaveChanges:=wdDoNotSaveChanges
 
    Set myDoc = Nothing
    
End Sub 
If your not already in word, you'll have to create an instance of it to work with.
 
Is that what you meant? 
K :-)
gsouza
02-18-2005, 06:54 AM
What I mean is on one of my userforms I have a Webbrowser control.  The control itself is smaller then the webpage or word document or any view it is showing at the time.  What I need is to be able to print the whole view of the document, weather word or a webpage not just the section that is currently showing in the control.  In other words I don't want to print the userform i want to print the webpage or document that is inside the webbrowser control in its entirety. I hope this is better but it is not easy to explain
gsdonald
11-05-2005, 01:53 AM
Hi Gsouza,
I guess I'm in the same boat as you ...
I'd like to print the <CONTENTS> of my webbrowser control, too (and not the userform that contains it). 
Did you get a solution?
 
GSD,
Ivan F Moala
11-05-2005, 04:01 PM
have you tried
On Error Resume Next
Me.WebBrowser1.ExecWB OLECMDID_PRINT, OLECMDEXECOPT_DODEFAULT, 0, 0
gsdonald
11-05-2005, 04:50 PM
Hi Ivan,
Thanks for the idea and to be honest I hadn't tried that function; I'm pretty new to VBA.
Now that I have, though, I get an error message. 
The "webpage" I want to print is in a userform in Excel. 
Is that any help?
 
Thanks again,
GSD
Shazam
11-05-2005, 06:48 PM
I assume that you have a image control on your userform so tried to use this code. It works for me. It will print out the image that is displayed on your userform.
 
 
Private Sub CommandButton3_Click()
PicPath = "C:\Mypicture\"
ffname = PicPath & tbxpartnr & ".jpg"
Worksheets.Add
ActiveSheet.Name = "Picture"
With ActiveSheet.PageSetup
.CenterHeader = tbxpartnr
.CenterFooter = mystyle
.Orientation = xlLandscape
End With
On Error Resume Next
Image1.Picture = LoadPicture("C:\MyPicture\" & tbxpartnr & ".jpg")
If Err = "53" Then
MsgBox "Need to display picture "
End If
ActiveSheet.Pictures.Insert(ffname).Select
Selection.ShapeRange.Height = 375.75
Selection.ShapeRange.Width = 564.75
ActiveWindow.SelectedSheets.PrintOut From:=1, To:=1, Copies:=1, Collate _
:=True
Sheets("Picture").Select
Application.DisplayAlerts = False
ActiveWindow.SelectedSheets.Delete
Application.DisplayAlerts = True
End Sub
 
 
Or you could do a Snap shot on your userForm but it will print out the whole userform.
 
 
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 = 44 
Public Const VK_LMENU = 164 
Public Const KEYEVENTF_KEYUP = 2 
Public Const KEYEVENTF_EXTENDEDKEY = 1 
 
 
 
 
 
 
 
 
In the Userform module: 
Private Sub CommandButton3_Click() 
' keybd_event VK_SNAPSHOT, 0, 0, 0 
DoEvents 
keybd_event VK_LMENU, 0, KEYEVENTF_EXTENDEDKEY, 0 
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
Ivan F Moala
11-06-2005, 12:05 AM
GSD
As an interim fix you could always right click the Webrowser and select Print.
Or
Ctrl + P
gsdonald
11-06-2005, 12:40 AM
Hi again,
And thanks to both (the right-clicking obviously works fine), but I'd rather find a more "practical way" of solving this one.
There must be a way to print a WebBrowser embedded in a userform in Excel.
 
GSD
Powered by vBulletin® Version 4.2.5 Copyright © 2025 vBulletin Solutions Inc. All rights reserved.