使用VBA将Infopath附件下载到硬盘中

时间:2017-06-14 10:12:47

标签: xml vba infopath

我有大约1000 xml的infopath文档,其中包含附件。我正在寻找一种通过VBA将infopath附件下载到我的驱动器中的方法,但我无法找到任何关于此的信息。任何代码或教程将不胜感激。

谢谢!

1 个答案:

答案 0 :(得分:0)

你是什么意思'下载'?来自网络?试试这个。

Sub Test()
 Dim FileNum As Long
 Dim FileData() As Byte
 Dim MyFile As String
 Dim WHTTP As Object

 On Error Resume Next
 Set WHTTP = CreateObject("WinHTTP.WinHTTPrequest.5")
 If Err.Number <> 0 Then
 Set WHTTP = CreateObject("WinHTTP.WinHTTPrequest.5.1")
 End If
 On Error GoTo 0

 MyFile = "website xxxx.com"

 WHTTP.Open "GET", MyFile, False
 WHTTP.Send here is where I stop. This is the error message:
 "Run-time error '-2147012867 (80072efd)':
A connection with the server could not be established"
 FileData = WHTTP.ResponseBody
 Set WHTTP = Nothing

 If Dir("c:\test", vbDirectory) = Empty Then MkDir "c:\test"

 FileNum = FreeFile
 Open "the file I downloaded " For Binary Access Write As #FileNum
 Put #FileNum, 1, FileData
 Close #FileNum

 MsgBox "Open the folder [ c:\test] for the downloaded file..."
 End Sub

另外,看看这个。

https://social.msdn.microsoft.com/Forums/en-US/bd0ee306-7bb5-4ce4-8341-edd9475f84ad/excel-2007-use-vba-to-download-save-csv-from-url