|
[广告] Excel易用宝 - 提升Excel的操作效率 · Excel / WPS表格插件 ★ 免费下载 ★ ★ 使用帮助★
写代码的电脑电脑系统:win7
office版本:office2007
第二台电脑:
电脑系统:XP
office版本:office2007
问题描述:
代码在“写代码的电脑”上能获取到值,把excel文件复制到“第二台电脑”,就无法获取到值了。
求大神指点!!!
- Sub test()
- Dim i As Long
- i = readWeb '调用自定义函数
- ThisWorkbook.Sheets(1).Range("a1").Value = i
- End Sub
- Private Function readWeb() As Long
- Dim regx As Object
- Dim reStr As String
- Dim mat As Object
- Dim URL As String
-
- readWeb = -1
-
- On Error Resume Next
-
- Set regx = CreateObject("VBScript.Regexp")
- regx.Pattern = "pk=(\d{1,3})"
-
-
- URL = "https://gitee.com/dsf4/jq/tree/master"
-
- 'With CreateObject("MSXML2.ServerXMLHTTP")
- With CreateObject("MSXML2.ServerXMLHTTP.6.0")
- .Open "GET", URL, False
- .Send
-
- TimeDelay (1) '调用自定义函数(等待1秒)
-
- If .Status = 200 Then '这里是True
-
- Set mat = regx.Execute(.responseText) '换一台电脑这里获取不到值,mat仍然是Nothing
-
- '我写代码的电脑能够正常获取到值:320
- readWeb = Val(mat(0).submatches(0))
-
- End If
-
- End With
-
- End Function
- '等待
- Private Function TimeDelay(ByVal PauseSecond As Single)
- Dim Star As Single
- Dim PauseTime As Single
- Star = Timer
- PauseTime = PauseSecond
- Do While Timer < Star + PauseTime
- DoEvents
- Loop
- End Function
复制代码
为什么更换电脑后无法获取网页数据?.rar
(10.73 KB, 下载次数: 0)
|
|