Created
April 13, 2016 14:30
-
-
Save timhall/64dff8d3c7f9da3085c0c047dcd0848c to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sub PostFiles() | |
' Note: Add reference to Microsoft Scripting Runtime | |
' (Tools > References) | |
' References: | |
' http://www.xl-central.com/list-files-fso.html | |
' http://stackoverflow.com/a/20391100/1240745 | |
Dim FSO As New FileSystemObject | |
Dim XmlFolder As Folder | |
Dim XmlFile As File | |
Dim XmlStream As TextStream | |
Set XmlFolder = FSO.GetFolder("C:\xml\") | |
If XmlFolder.Files.Count = 0 Then | |
' No files found... | |
Exit Sub | |
End If | |
' Setup Client and most of Request outside of loop | |
Dim Client As New WebClient | |
Dim Request As New WebRequest | |
Dim Response As WebResponse | |
Client.BaseUrl = "https://webservice.../" | |
Request.Resource = "xml/{filename}" | |
For Each XmlFile In XmlFolder.Files | |
Request.AddUrlSegment "filename", XmlFile.Name | |
XmlTextStream = XmlFile.OpenAsTextStream(1) | |
Request.Body = XmlTextStream.ReadAll | |
XmlTextStream.Close | |
Set Response = Client.Execute(Request) | |
' Check Immediate Window (ctrl + g) | |
Debug.Print XmlFile.Name & " -> " & Response.StatusCode & ": " & Response.Content | |
Next XmlFile | |
End Sub |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment