I am having a problem getting my VBA code to print a web page. The code is initiated by a button click event from within an Access form. The intent is to:
1) Start Internet Explorer.
2) Navigate to a specific web site containing a form.
3) Push data into the web form.
4) Submit the form.
5) Print the resulting web page.
6) Close and exit IE.
I cannot get the IE page to print. I have attempted the print method many ways with errors each time.
Can anyone help me with syntax of the print method to complete this function?
Thanks,
Rick46
Below is my code:
Private Sub IEForm_Click()
Dim myStart As Variant
Dim myFinish As Variant
Dim IExplorer As Object
Set IExplorer = CreateObject("InternetExplorer.Application"
'*** Start IE, go to URL
With IExplorer
.Navigate " .Visible = True
'*** Allow time for IE to navigate
myStart = Timer
Do While True
DoEvents
myFinish = Timer
If myFinish - 5 > myStart Then Exit Do
Loop
'*** Push data into IE form
IExplorer.Document.Forms(0).SENDERNAME.Value = "Doe, John"
IExplorer.Document.Forms(0).CONSIGNCOMPANY.Value = "TESTCOMPANY,INC"
IExplorer.Document.Forms(0).CONSIGNADDRESS1.Value = "999 Streetname"
IExplorer.Document.Forms(0).CONSIGNCITY.Value = "Any City"
IExplorer.Document.Forms(0).CONSIGNSTATE.Value = "IN"
IExplorer.Document.Forms(0).CONSIGNZIP.Value = "47374"
IExplorer.Document.Forms(0).CHARGEBACKCENTER.Value = "H270000"
IExplorer.Document.Forms(0).PACKAGEDSC.Value = "THIS IS A TEST"
'*** Submit form
IExplorer.Document.Forms(0).SUBMIT.Click
End With
'*** Allow time for IE to navigate
myStart = Timer
Do While True
DoEvents
myFinish = Timer
If myFinish - 5 > myStart Then Exit Do
'*** Print the displayed IE web page
IExplorer.Window.Print '<---- Cannot get to work *****
'*** Allow time for completion
myStart = Timer
Do While True
DoEvents
myFinish = Timer
If myFinish - 5 > myStart Then Exit Do
'*** Close IE
IExplorer.Quit
'*** Cleanup
Set IExplorer = Nothing
MsgBox "Your barcode sheet has been printed"
End Sub
1) Start Internet Explorer.
2) Navigate to a specific web site containing a form.
3) Push data into the web form.
4) Submit the form.
5) Print the resulting web page.
6) Close and exit IE.
I cannot get the IE page to print. I have attempted the print method many ways with errors each time.
Can anyone help me with syntax of the print method to complete this function?
Thanks,
Rick46
Below is my code:
Private Sub IEForm_Click()
Dim myStart As Variant
Dim myFinish As Variant
Dim IExplorer As Object
Set IExplorer = CreateObject("InternetExplorer.Application"
'*** Start IE, go to URL
With IExplorer
.Navigate " .Visible = True
'*** Allow time for IE to navigate
myStart = Timer
Do While True
DoEvents
myFinish = Timer
If myFinish - 5 > myStart Then Exit Do
Loop
'*** Push data into IE form
IExplorer.Document.Forms(0).SENDERNAME.Value = "Doe, John"
IExplorer.Document.Forms(0).CONSIGNCOMPANY.Value = "TESTCOMPANY,INC"
IExplorer.Document.Forms(0).CONSIGNADDRESS1.Value = "999 Streetname"
IExplorer.Document.Forms(0).CONSIGNCITY.Value = "Any City"
IExplorer.Document.Forms(0).CONSIGNSTATE.Value = "IN"
IExplorer.Document.Forms(0).CONSIGNZIP.Value = "47374"
IExplorer.Document.Forms(0).CHARGEBACKCENTER.Value = "H270000"
IExplorer.Document.Forms(0).PACKAGEDSC.Value = "THIS IS A TEST"
'*** Submit form
IExplorer.Document.Forms(0).SUBMIT.Click
End With
'*** Allow time for IE to navigate
myStart = Timer
Do While True
DoEvents
myFinish = Timer
If myFinish - 5 > myStart Then Exit Do
'*** Print the displayed IE web page
IExplorer.Window.Print '<---- Cannot get to work *****
'*** Allow time for completion
myStart = Timer
Do While True
DoEvents
myFinish = Timer
If myFinish - 5 > myStart Then Exit Do
'*** Close IE
IExplorer.Quit
'*** Cleanup
Set IExplorer = Nothing
MsgBox "Your barcode sheet has been printed"
End Sub