【发布时间】:2014-07-24 01:13:44
【问题描述】:
因此,我正在为我的部门编写此代码,该代码将转到网站输入数据,单击运行并将 csv 文件下载到工作表。它在我的 PC 和其他部门使用的计算机上的个人资料上运行良好。我们都使用相同版本的 windows、excel 和 IE。当我让其他部门的人运行宏时,它会打开网站,但从不将数据输入到字段中,尽管该网站的编码与我登录时完全相同。
Sub testmetric()
Dim appIE As Object
Dim Obj As Object
On Error Resume Next
Sheets("Audit").Select
Selection.AutoFilter
Sheets("Audit").Cells.Clear
Application.ScreenUpdating = False
Application.ScreenUpdating = True
Set appIE = CreateObject("InternetExplorer.Application")
sURL = "http://cctools/rportal/main.php?p=agentavaya"
' Instructes the macro to open IE and navigate to sURL.
With appIE
.Navigate sURL
.Visible = True
Application.Wait Now + TimeValue("00:00:02")
Set HTMLDOC = .Document
End With
Application.Wait Now + TimeValue("00:00:02")
appIE.Document.getElementById("agentLob").selectedIndex = "3"
appIE.Document.getElementById("timezone").selectedIndex = "1"
appIE.Document.getElementById("sdate").Value = Range("Date_Start")
appIE.Document.getElementById("edate").Value = Range("Date_End")
appIE.Document.getElementById("stenure").Value = Range("TenStart")
appIE.Document.getElementById("etenure").Value = Range("TenEnd")
Application.Wait Now + TimeValue("00:00:02")
For Each Btninput In appIE.Document.getElementsByTagName("INPUT")
If Btninput.Value = " Run " Then
Btninput.Click
Exit For
End If
Next
Application.Wait Now + TimeValue("00:00:02")
Call CSV
appIE.Quit
Sheets("Audit").Select
Range("A1").Select
Sheets("audit").Paste
End Sub
Sub CSV()
sCSVLink = "http://cctools/rportal/csvexport.php"
sfile = "csvexport.php"
ssheet = "Sheet10"
Set wnd = ActiveWindow
Application.ScreenUpdating = False
Workbooks.Open Filename:=sCSVLink
Windows(sfile).Activate
ActiveSheet.Cells.Copy
wnd.Activate
Range("A1").Select
Sheets("Audit").Paste
Application.DisplayAlerts = False
Windows(sfile).Close False
Application.DisplayAlerts = True
Application.ScreenUpdating = True
Sheets("Audit").Select
Range("A1").Select
Sheets("audit").Paste
End Sub
当此代码由其他部门的成员运行时,它只会打开网站,不输入任何内容,也不会按网站上的“运行”按钮。
关于可能导致此问题的任何想法?什么设置什么的。我验证了两个 PC 的 VBA 引用都在那里,并且没有 "Locations are missing paths" 。
【问题讨论】:
-
第一步是注释掉
On Error Resume Next -
谢谢蒂姆。我将返回修复该问题的结果。有点打我的头,因为应该想到这一点来显示它存在什么错误。非常感谢你。如果我无法修复它,希望您关注以防遇到更多错误。
-
您笼统地假设 4 秒始终足以加载文档,我保证并非总是如此。如果您尝试在文档准备好之前访问该文档,您的代码将会失败。使用等待循环:stackoverflow.com/questions/19334880/…
-
可能是安全设置不同。在两个浏览器中打开 Internet 选项 -> 安全 -> 自定义级别并查找差异。
标签: html excel vba internet-explorer