我是这个网站的新手以及vba和html(开始学习/使用两个月之前)所以请原谅我的质量问题。我在下面提到的代码就是我用来将excel文件中的值上传到网站上的代码。我挣扎的部分是 SetCursorPos x,y 。所以要解释为什么我首先要有那个:我需要点击一个按钮"添加"在最初通过单击另一个按钮" Add Client"召唤的用户表单的底部。出于某种原因,。点击并不在这里工作。所以为了解决这个问题,我在网上找到了模拟鼠标点击的代码。这有效但我需要将光标放在"添加"按钮我自己。我确实发现我可以使用SetCursorPos函数将光标放在我需要的位置,但我不知道如何首先获得按钮的x,y坐标。我尝试过解析源代码,但是我无法找到按钮对象所需的所有位置信息。如果我点击"布局"当我选择了与“添加”按钮对应的html代码时,我会看到我要查找的信息,但我也不知道如何提取这些信息。我没有从我的在线搜索中得到任何结果。有什么建议或想法吗?
提前谢谢。
Sub JoistUpload()
Dim TextFile As Integer
Dim FilePath As String
Dim FileContent As String
Dim NumberOfModulesToRun As Integer
NumberOfModulesToRun = ThisWorkbook.Sheets("Overall").Range("B12").Value
Dim ModulesToRun() 'Dynamic Array
ReDim ModulesToRun(NumberOfModulesToRun - 1)
j = 0
For i = 2 To 10
If ThisWorkbook.Sheets("Overall").Cells(i, 2).Value = 1 Then
ModulesToRun(j) = ThisWorkbook.Sheets("Overall").Cells(i, 1).Value
j = j + 1
End If
Next i
Set objIE = CreateObject("InternetExplorer.Application")
With objIE
.Visible = True
.Navigate "https://my.joistapp.com/dashboard/estimate/new"
Do While .Busy Or .readyState <> 4
DoEvents
Loop
Application.Wait (Now + TimeValue("0:00:10"))
.Document.GetElementsByClassName("ember-view document-header-client waves-effect waves-green btn-flat")(0).Click
.Document.getElementbyID("name").Value = ThisWorkbook.Sheets("Overall").Range("O2").Text
.Document.getElementbyID("email").Select
Application.SendKeys ThisWorkbook.Sheets("Overall").Range("O3").Text, True
Application.Wait (Now + TimeValue("0:00:2"))
.Document.getElementbyID("phoneMobile").Select
Application.SendKeys ThisWorkbook.Sheets("Overall").Range("O4").Text, True
Application.Wait (Now + TimeValue("0:00:2"))
.Document.getElementbyID("phoneOther").Select
Application.SendKeys ThisWorkbook.Sheets("Overall").Range("O5").Text, True
Application.Wait (Now + TimeValue("0:00:2"))
.Document.getElementbyID("address1").Select
Application.SendKeys ThisWorkbook.Sheets("Overall").Range("O7").Text, True
Application.Wait (Now + TimeValue("0:00:2"))
.Document.getElementbyID("address2").Select
Application.SendKeys ThisWorkbook.Sheets("Overall").Range("O8").Text, True
Application.Wait (Now + TimeValue("0:00:2"))
.Document.getElementbyID("city").Select
Application.SendKeys ThisWorkbook.Sheets("Overall").Range("O9").Text, True
Application.Wait (Now + TimeValue("0:00:2"))
.Document.getElementbyID("state").Select
Application.SendKeys ThisWorkbook.Sheets("Overall").Range("O10").Text, True
Application.Wait (Now + TimeValue("0:00:2"))
.Document.getElementbyID("zip").Select
Application.SendKeys ThisWorkbook.Sheets("Overall").Range("O11").Text, True
Application.Wait (Now + TimeValue("0:00:2"))
.Document.getElementbyID("ember1872").Select
Application.SendKeys ThisWorkbook.Sheets("Overall").Range("O12").Text, True
Application.Wait (Now + TimeValue("0:00:02"))
'SetCursorPos x, y
mouse_event MOUSEEVENTF_LEFTDOWN, 0, 0, 0, 0
mouse_event MOUSEEVENTF_LEFTUP, 0, 0, 0, 0
For i = 0 To NumberOfModulesToRun - 1
FilePath = "C:\Users\Bloom\Documents\Renovation Express\Quote Code\" & ModulesToRun(i) & "Module.txt"
TextFile = FreeFile
Open FilePath For Input As TextFile
FileContent = Input(LOF(TextFile), TextFile)
.Document.GetElementsByClassName("ember-view waves-effect waves-green new-document-item btn-green btn-flat waves-effect waves-light button-with-image")(0).Click
.Document.GetElementsByClassName("ember-view btn-green btn waves-effect waves-light")(2).Click
.Document.GetElementsByClassName("unstyled materialize-textarea ember-view ember-text-area")(i).Value = FileContent
.Document.GetElementsByClassName("no-padding unstyled is-valid ember-view ember-text-field")(i).Value = ModulesToRun(i)
.Document.GetElementsByClassName("no-padding unstyled ember-view ember-text-field")(3 * (i) + 1).Value = ThisWorkbook.Sheets("Overall").Range("A:A").Find(What:=ModulesToRun(i)).Offset(0, 3).Value
.Document.GetElementsByClassName("document-tax-col placeholder")(0).Click
.Document.GetElementsByClassName("toggle-bar")(3).Click
.Document.GetElementsByClassName("ember-view btn-green btn waves-effect waves-light")(3).Click
Close TextFile
Next i
FilePath = "C:\Users\Bloom\Documents\Renovation Express\Quote Code\NoteForClient.txt"
TextFile = FreeFile
Open FilePath For Input As TextFile
FileContent = Input(LOF(TextFile), TextFile)
.Document.GetElementsByClassName("materialize-textarea ember-view ember-text-area")(NumberOfModulesToRun).Value = FileContent
Close TextFile
.Document.getElementbyID("issued-date").Click
.Document.GetElementsByClassName("btn-flat picker__today")(0).Click
End With
End Sub
与“添加”按钮所在的表单相关的一些源代码:
</p></div></div></div></div></div></div></div></section><div
class="modaler"><div class="modal modal-view" style="top: 70.3px; width:
700px; height: 562.4px; display: block; min-height: 0px; max-width: 700px;"
data-is-push="false"><div class="ember-view modal-wrapper" id="ember1841">
<div class="modal-header"><div class="title"><!----><span>New Client</span>
</div><div class="actions"><a class="ember-view btn-green btn waves-effect
waves-light" id="ember1842"><!----><span>My Clients</span><!----></a></div>
</div><div class="modal-content"><p><div class="ember-view" id="ember1851">
<div class="ember-view col-header form-header" id="ember1860"><h3
class="col-header-title">Basic Information</h3></div><div class="ember-view
fixed-label input-field is-valid" id="ember1861"><div class="joist-input-
container-wrapper"><input class=" is-valid ember-view ember-text-field"
id="name" type="text"><label class="false active" for="name">Name</label><!-
---></div><!----></div><div class="ember-view fixed-label input-field is-
valid" id="ember1862"><div class="joist-input-container-wrapper"><input
class=" is-valid ember-view ember-text-field" id="email" type="text">
<label class="false" for="email">Email Address</label><!----></div><!---->
</div><div class="ember-view fixed-label input-field is-valid"
id="ember1863"><div class="joist-input-container-wrapper"><input class="
is-valid ember-view ember-text-field" id="phoneMobile" type="text"><label
class="false" for="phoneMobile">Phone (mobile)</label><!----></div><!---->
</div><div class="ember-view fixed-label input-field is-valid"
id="ember1864"><div class="joist-input-container-wrapper"><input class="
is-valid ember-view ember-text-field" id="phoneOther" type="text"><label
class="false" for="phoneOther">Phone (other)</label><!----></div><!---->
</div><div class="ember-view col-header form-header" id="ember1865"><h3
class="col-header-title">Additional Information</h3></div><div class="ember-
view fixed-label input-field is-valid" id="ember1866"><div class="joist-
input-container-wrapper"><input class=" is-valid ember-view ember-text-
field" id="address1" type="text"><label class="false"
for="address1">Address</label><!----></div><!----></div><div class="ember-
view fixed-label input-field is-valid" id="ember1867"><div class="joist-
input-container-wrapper"><input class=" is-valid ember-view ember-text-
field" id="address2" type="text"><label class="false" for="address2">Address
2</label><!----></div><!----></div><div class="ember-view fixed-label input-
field is-valid" id="ember1868"><div class="joist-input-container-wrapper">
<input class=" is-valid ember-view ember-text-field" id="city"
type="text"><label class="false" for="city">City</label><!----></div><!---->
</div><div class="ember-view fixed-label input-field is-valid"
id="ember1869"><div class="joist-input-container-wrapper"><input class="
is-valid ember-view ember-text-field" id="state" type="text"><label
class="false" for="state">State</label><!----></div><!----></div><div
class="ember-view fixed-label input-field is-valid" id="ember1870"><div
class="joist-input-container-wrapper"><input class=" is-valid ember-view
ember-text-field" id="zip" type="text"><label class="false" for="zip">Zip /
Postal Code</label><!----></div><!----></div><div class="ember-view input-
field input-field-textarea fixed-label input-field is-valid" id="ember1871">
<div class="joist-input-container-wrapper"><textarea class="materialize-
textarea ember-view ember-text-area" id="ember1872" style="height: 23px;">
<!----><br></textarea><label class="false">Private Notes</label></div></div>
</div></p></div><div class="modal-action"><!----><a class="ember-view btn-
grey btn waves-effect waves-light" id="ember1873"><!----><span>Cancel</span>
<!----></a><a class="ember-view btn-green btn waves-effect waves-light"
id="ember1874"><!----><span>Add</span><!----></a></div></div></div></div>
<div class="modal fade alert-view"><!----></div><div class="ember-view
select-view" id="ember679"><!----></div><div class="loading-overlay"
style="display: none;" data-ember-action="680"></div></div><div
class="material-tooltip"><span>Estimates</span><div class="backdrop"
style="left: 0px; top: 0px;"></div></div><div class="material-tooltip">
<span>Invoices</span><div class="backdrop" style="left: 0px; top: 0px;">
</div></div><div class="material-tooltip"><span>Clients</span><div
class="backdrop" style="left: 0px; top: 0px;"></div></div><div
class="material-tooltip"><span>Items</span><div class="backdrop"
style="left: 0px; top: 0px;"></div></div><div class="material-tooltip">
<span>Settings</span><div class="backdrop" style="left: 0px; top: 0px;">