きぬあさ殿
返信ありがとうございます。
すいません。コードを載せるべきでしたね。
Sendメソッドの引数はVariant型ですが、エラーが出ています。
※最初にXP環境で組んだとき、Variant型にしていなくてうまくいかななったので
該当部分のコードは以下の通りです。
' -----------------------------------------------
' WinHttpRequestでPost処理
'
' uploadURL String 転送先のアドレス
' bFormData Byte() 転送するデータ
' Boundary String Boundary情報
' -----------------------------------------------
Function WinHttpRequest( _
ByVal uploadURL As String, _
ByRef bFormData() As Byte, _
ByVal Boundary As String, _
ByVal cookie As String _
) As String
On Error GoTo ErrHandlerEnd
'WinHttpRequestオブジェクト作成
Dim http As Object
Set http = CreateObject("WinHttp.WinHttpRequest.5.1")
If Err.Number <> 0 Then
Err.Clear
Set http = CreateObject("WinHttp.WinHttpRequest.5")
If Err.Number <> 0 Then
Err.Clear
Set http = CreateObject("WinHttp.WinHttpRequest")
If Err.Number <> 0 Then
WinHttpRequest = "動作環境はWindows 2000以上である必要があります" 'TODO
Exit Function
End If
End If
End If
' Post処理
Dim vData As Variant ' String や Byte()だとうまくフォームデータが送信されない
vData = bFormData
http.Open "POST", uploadURL, False ' False = 同期実行
http.SetRequestHeader "Cookie", cookie ' Excelシート経由で引き継がれたCookieをセット
' マルチパート
http.SetRequestHeader "Content-Type", "multipart/form-data; boundary=" + Boundary
http.Send vData ' 送信
' 結果確認
If (http.Status >= 200 And http.Status < 300) Then
WinHttpRequest = http.ResponseText
Else
MsgBox http.Status & ": " & http.StatusText
WinHttpRequest = ""
End If
' メモリ開放
Set http = Nothing
On Error GoTo 0
Exit Function
ErrHandlerEnd:
MsgBox "Post処理で異常終了しました。"
MsgBox Err.Number & ": " & Hex(Err.Number) & ": " & Err.Description
End Function