|
发表于 2013-7-17 14:56
|
显示全部楼层
本楼为最佳答案
- Sub getdate()
- On Error Resume Next
- Dim objXML As Object
- Dim strTemp As String
- Dim lStart As Long
- Dim lEnd As Long
- Dim DtWeb As Date
- Dim arr() As String
-
- DtWeb = #12/31/2010# '设置默认返回时间
- '建立XMLHTTP对象。并获取<A href="http://www.timeanddate.com/worldclock/city.html?n=33">http://www.timeanddate.com/worldclock/city.html?n=33</A>的网页Text
- '&Refresh=" & Rnd 是为了避免直接从IE缓存中读取
- Set objXML = CreateObject("Microsoft.XMLHTTP")
- Randomize '初始化随机数,避免IE缓存重复
- objXML.Open "Get", "<A href="http://www.timeanddate.com/worldclock/city.html?n=33&Refresh">http://www.timeanddate.com/worldclock/city.html?n=33&Refresh</A>=" & Rnd, False '读取北京时间
- objXML.sEnd ""
- strTemp = objXML.responseText</P>
- '对网页进行处理,找出当前日期和时间
- lStart = InStr(1, strTemp, "Current Time", vbTextCompare)
- lEnd = InStr(lStart, strTemp, "</strong>", vbTextCompare)
- strTemp = Mid(strTemp, lStart, lEnd - lStart)</P>
- strTemp = Replace(strTemp, "Current Time</th><td><strong id=ct class=big>", "")
-
- arr() = Split(strTemp, ",", -1, vbTextCompare)
- DtWeb = CDate(arr(1) & arr(2))
- Set objXML = Nothing
- '活动单元格输出日期和时间
- ActiveCell.Value = DtWeb
- End Sub
复制代码 |
|