我一直在尝试为我的工作流程创建登录。有些网站有效。
此链接几乎是一个答案,除了未定义ieObj。 vba automation in Internet Explorer - clicking different buttons on successive webpages not working?
这就是我所拥有的。小心翼翼。斜体是变量引用。通常这很好用。这个网站上的按钮虽然没有“名称”。只是一个类,Onclick和Title(但标题是“”null)。我试过.getelementbytagName(Button),. getelementbyclassname(“ButtonThemeA”)和其他一些东西。按钮点击部分始终出现错误。
如何引用此按钮并单击它?
我得到一个运行时错误'438'; Object不支持此属性或方法。
Sub Login1()
Dim ieApp As InternetExplorer
Dim ieDoc As Object
Dim LoginVal As String
Dim PassVal As String
Dim ieForm As Object
Dim ieObj As Object
'create a new instance of ie
Set ieApp = New InternetExplorer
'you don’t need this, but it’s good for debugging
ieApp.Visible = True
'Login Screen
ieApp.Navigate "*webpage to login*"
Do While ieApp.Busy: DoEvents: Loop
Do Until ieApp.ReadyState = READYSTATE_COMPLETE: DoEvents: Loop
'Get the login values
LoginVal = Workbooks("Macrobook").Sheets("Login").Cells(2, 3).Value
PassVal = Workbooks("Macrobook").Sheets("Login").Cells(2, 4).Value
Set ieDoc = ieApp.Document
'fill in the login form
With ieDoc
.getElementById("usr_name").Value = LoginVal
.getElementById("usr_password").Value = PassVal
.getElementbyTagName(button).Click
End With
Do While ieApp.Busy: DoEvents: Loop
Do Until ieApp.ReadyState = READYSTATE_COMPLETE: DoEvents: Loop
'To acct list screen
ieApp.Navigate "*Acct list URL - Not important for this question*"
Do While ieApp.Busy: DoEvents: Loop
Do Until ieApp.ReadyState = READYSTATE_COMPLETE: DoEvents: Loop
'And it goes on from here.
End Sub
如果是“提交”按钮,则不需要名称(或该按钮的ID)。你需要的是表格“id”。然后你可以说:iedocument.form("formname").submit
我用这种方式使用它:
Sub website_newtitle()
target_form = "model-node-form" '<-- THE FORM ID
target_url = ThisWorkbook.Sheets("models").Cells(1, 1).Value
new_title = ThisWorkbook.Sheets("models").Cells(1, 2).Value
'Modification
Dim ie As New InternetExplorer
Dim LookUpValue As String
Dim HtmlDoc As HTMLDocument
Dim SubmitInput As HTMLInputElement
ie.Navigate target_url
Do Until ie.ReadyState = READYSTATE_COMPLETE 'wait till the page is loaded
Loop
Set HtmlDoc = ie.document
With ie
.Visible = True 'disable to remain invisible
.AddressBar = True
.Toolbar = True
End With
HtmlDoc.forms(target_form).elements("edit-title").Value = new_title
'submit data
HtmlDoc.Forms(target_form).Submit '<-- SUBMIT THE FORM
Do Until ie.ReadyState = READYSTATE_COMPLETE 'wait till the page is loaded
'close window
ie.Quit
End Sub