I Have some code that goes through cells in my spreadsheet opens the hyperlink in the cells, Puts in logging information and prints the file.
Here is the code i use for this
Sub OpenandPrintURLinIE()
Dim FilePath, CurrentWB
Dim PrintRng As Range
Dim myURL As String
Dim IElocation As String
Dim myIE As New InternetExplorer
Dim myURLx As String
Dim myDoc As HTMLDocument
Dim strPass As String
Dim StrName As String
'the range in excel that should be printed
Set PrintRng = Range("WeldPrint")
CurrentWB = ThisWorkbook.Name
For Each Cell In PrintRng
Workbooks(CurrentWB).Activate
Cell.Select
'check if there is an actual hyperlink in cell
If ActiveCell.Value = "-" Then GoTo Line2 Else GoTo Line1
Line1: 'if there is a hyperlink code starts here
If ActiveCell.Value = "" Then Exit Sub
FilePath = Selection.Hyperlinks(1).Address
'the input values
strPass = xxxx
StrName = yyyy
'filepath to webfor to fill
myURL = FilePath
myIE.navigate myURL
myIE.Visible = True
'wait until IE has loaded. This is the part that bugs for me
Do While myIE.Busy Or myIE.readyState <> READYSTATE_COMPLETE
DoEvents
Loop
Set myDoc = myIE.document
'Input the values in the webform
myDoc.forms(0).userPswd.Value = strPass
myDoc.forms(0).useradr.Value = StrName
'From here on it just open the page and prints it
Sleep 2000
SendKeys "~"
Sleep 4000
SendKeys "^p", True
'Delay a second before entering OK
Sleep 2000
'Send <Enter> to print
SendKeys "~", True
'Delay five seconds so printjob can be spooled before closing IE
Sleep 5000
' Send <ALT>+F4 to close IE
SendKeys "%{F4}", True
Line2:
Next Cell
End Sub
The filepath is a variation of https://service.projectplace.com/pp/start.cgi? but if you put in that adress you can see the elements that you need.
This is the part of the code atm that i have problem with
Do While myIE.Busy Or myIE.readyState <> READYSTATE_COMPLETE
DoEvents
Loop
i get an automatation error, undefined error.
When i first implented the code everything worked, but the second day when i was gonna try it out, it didnt work and it hasnt been working since then. I have tried diffrent methods of this oart of the code but i cant get it to work anymore.
Anyone that have any idea?
Bookmarks