vba 在 MS Access 中从网站导入数据
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/7062959/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Import data from web site in MS Access
提问by SteMa
I want to write an import function for importing data from a website into a ms access database. The original data is stored in a mysql database and is available via a remote text file (csv). So all I want is to access this remote file and read it in vba. The code I use is below, but it seems that references are missing. Don't know which reference ActiveXperts.Http needs. Could anybody help?
我想编写一个导入函数,用于将数据从网站导入到 ms access 数据库中。原始数据存储在 mysql 数据库中,可通过远程文本文件 (csv) 获得。所以我只想访问这个远程文件并在 vba 中读取它。我使用的代码如下,但似乎缺少引用。不知道 ActiveXperts.Http 需要哪个引用。有人可以帮忙吗?
Thx Steve
谢谢史蒂夫
Dim objHttp
Dim strUrl
Dim strData
' Create a HTTP instance
Set objHttp = CreateObject("ActiveXperts.Http")
' Write some information to console
MsgBox "ActiveSocket " & objHttp.Version & " demo."
MsgBox "Expiration date: " & objHttp.ExpirationDate & vbCrLf
Do
strUrl = InputBox("Enter a URL", "Input", "www.activexperts.com/products")
Loop Until strUrl <> ""
objHttp.LogFile = "C:\HttpLog.txt"
objHttp.Connect (strUrl)
If (objHttp.LastError <> 0) Then
MsgBox "Error " & objHttp.LastError & ": " & objHttp.GetErrorDescription(objHttp.LastError)
Else
strData = objHttp.ReadData
If (objHttp.LastError <> 0) Then
MsgBox "Error " & objHttp.LastError & ": " & objHttp.GetErrorDescription(objHttp.LastError)
Else
MsgBox strData
End If
objHttp.Disconnect
MsgBox "Disconnect."
End If
MsgBox "Ready."
回答by Christian Specht
This tutorialsays that it needs ActiveSocket 2.4 Type Library
.
本教程说它需要ActiveSocket 2.4 Type Library
.
(the tutorial is for VB 5/6 and not VBA, but the reference stuff should be exactly the same)
(本教程适用于 VB 5/6 而不是 VBA,但参考资料应该完全相同)