Skip to content

Instantly share code, notes, and snippets.

@timhall
Created April 13, 2016 14:30
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save timhall/64dff8d3c7f9da3085c0c047dcd0848c to your computer and use it in GitHub Desktop.
Save timhall/64dff8d3c7f9da3085c0c047dcd0848c to your computer and use it in GitHub Desktop.
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