从http / ftp导入Module.bas?

时间:2016-01-04 15:47:34

标签: excel vba excel-2010

我想通过ftp / http导入模块。

例如: ThisWorkbook.VBProject.VBComponents.Import(“http://www.server.de/modul.bas”)

我想将模块的代码保存在中央文件中,但我们没有共享驱动器。所以我想将我的代码上传到某个服务器并不时更新它。

1 个答案:

答案 0 :(得分:0)

扩展蒂姆的评论。将其下载到临时文件夹并从那里导入。您可以使用以下代码下载文件。

Need reference to Microsoft Internet Controls
'Example
'myURL = "http://www.server.de/modul.bas"
'savePath = Environ("temp")
'fileName = "modul.bas"
Sub SaveInternetFile(myURL As String, savePath As String, fileName As String)
    Dim WinHttpReq As Object
    'create XMLHttp object
    Set WinHttpReq = CreateObject("Microsoft.XMLHTTP")
    WinHttpReq.Open "GET", myURL, False
    'send request
    WinHttpReq.send
    'check the status to make sure we succeeded
    If WinHttpReq.Status = 200 Then
        Set oStream = CreateObject("ADODB.Stream")
        oStream.Open
        oStream.Type = 1
        oStream.Write WinHttpReq.responseBody
        oStream.SaveToFile (savePath & fileName)
        oStream.Close   
    'import the new file
    ThisWorkbook.VBProject.VBComponents.Import(savePath & filename) 
    End If 
End Sub