gui*_*wer 5 excel vba add-in excel-vba online-forms
我正在尝试做这样的帖子,但使用Excel VBA.每次在Excel加载项上按下按钮时,我都想在google docs表单上提交回复.插件将是一个XLA文件,并用VBA编写.
我希望能够收集用户正在使用的功能.如果有人有更好的解决方案,我就会开放.
- -编辑 - -
这是我试图写的形式(其中一个字段的代码摘录.)
<div class="errorbox-good">
<div class="ss-item ss-item-required ss-text">
<div class="ss-form-entry">
<label for="entry_0" class="ss-q-title">
UserName
<span class="ss-required-asterisk">*</span>
</label>
<label for="entry_0" class="ss-q-help"></label>
<input type="text"
id="entry_0"
class="ss-q-short"
value=""
name="entry.0.single">
</div>
</div>
</div>
Run Code Online (Sandbox Code Playgroud)
--EDIT 2--这是我到目前为止所尝试过的,但它仍然没有用.我在".UserName.Value = Environ("username")的行上收到错误"我怀疑这是因为它找不到项目.username.
Private Sub GoogleForm()
Dim ie As Object
Set ie = CreateObject("InternetExplorer.Application")
On Error GoTo errHandler
With ie
.navigate "http://spreadsheets.google.com/viewform?hl=en&cfg=true&formkey=dHFTMzkwR2RpY2tzSUNnbVhIcDN3WWc6MA"
Do While .busy: DoEvents: Loop
Do While .ReadyState <> 4: DoEvents: Loop
With .document.Forms(1)
'Username
.UserName.Value = Environ("username")
'Key
.Key.Value = "00qwe-12ckd"
.submit
End With
Do While Not CBool(InStrB(1, .document.URL, _
"cp_search_response-e.asp"))
DoEvents
Loop
Do While .busy: DoEvents: Loop
Do While .ReadyState <> 4: DoEvents: Loop
MsgBox .document.all.tags("table").Item(11).Rows(1).Cells(7).innerText
End With
Exit Sub
errHandler:
ie.Quit: Set ie = Nothing
End Sub
Run Code Online (Sandbox Code Playgroud)
我能找到的最好的解决方案是使用 sendkeys。我知道这不太理想,但这里没有任何其他反馈,并且以我有限的知识,这是我能想到的最好的。我已经接受了这个答案,并且由于赏金请求,我无法撤消接受,但如果这里有更好的想法,我会投票并留下评论,说明这就是答案。
Sub FillOutGoogleForm()
Application.ScreenUpdating = False
Dim IE As Object
Dim uname As String
Dim ukey As String
uname = Environ("username")
ukey = "00000-123kd-34kdkf-slkf"
Set IE = CreateObject("InternetExplorer.Application")
IE.Visible = True
While IE.busy
DoEvents
Wend
IE.navigate "http://spreadsheets.google.com/viewform?hl=en&pli=1&formkey=dHFTMzkwR2RpY2tzSUNnbVhIcDN3WWc6MA"
While IE.busy
DoEvents
Wend
SendKeys uname
While IE.busy
DoEvents
Wend
SendKeys "{TAB}", True
SendKeys ukey
While IE.busy
DoEvents
Wend
SendKeys "{TAB}", True
SendKeys "{ENTER}", True
SendKeys "%{F4}"
Application.ScreenUpdating = True
End Sub
Run Code Online (Sandbox Code Playgroud)