2012-01-10 21 views
2

私はxmlhttpをvbaからExcel 2010で使用しています。プログラムで、ウェブサイトのショッピングカートに商品を追加する必要があります。私はこれまでのところコードを持っていますが、それはPOSTメソッドを使用していますvbaとxmlhttpのウェブサイトにある投稿フォームを自動送信する

私のコードに間違っていると思いますが、修正方法がわかりません - フォームが送信されている場所は表示されません。ここではそのURLは次のとおりです。私は、フォームを処理し、URLとして入力

http://www.craft-e-corner.com/p-2688-new-testament-cricut-cartridge.aspx

urlは「フォーム」の「アクション=」の部分でURLです。

フォームが投稿されたことを確認するにはどうすればよいですか?

Sub post_frm() 
Dim xmlhttp As Object 
Set xmlhttp = CreateObject("MSXML2.ServerXMLHTTP") 
' Indicate that page that will receive the request and the 
' type of request being submitted 
xmlhttp.Open "POST", "http://www.craft-e-corner.com/addtocart.aspx?returnurl=showproduct.aspx%3fProductID%3d2688%26SEName%3dnew-testament-cricut-cartridge", False 
' Indicate that the body of the request contains form data 
xmlhttp.setRequestHeader "Content-Type", "application/x-www-form-urlencoded" 
' Send the data as name/value pairs 
xmlhttp.send "Quantity=1&VariantID=2705&ProductID=2688" 
Set xmlhttp = Nothing 
End Sub 

答えて

6

コードに問題はありません。 :)私はそれをテストし、それは正常に動作します。エラーは別の場所にある可能性があります。

IEを使用して出力をテストするコードを微調整したところ、今はうまく動作しています。私は現時点でExcel 2007でテストしました。すぐに2010年にそれをテストします。どのバージョンのIEを使用していますか?

私がテストしたコードはここにあり、うまくいきます。

Option Explicit 

Sub post_frm() 

    Dim objIE As Object, xmlhttp As Object 
    Dim response As String 

    Set objIE = CreateObject("InternetExplorer.Application") 
    objIE.navigate "about:blank" 
    objIE.Visible = True 

    Set xmlhttp = CreateObject("MSXML2.ServerXMLHTTP") 

    '~~> Indicates that page that will receive the request and the type of request being submitted 
    xmlhttp.Open "POST", "http://www.craft-e-corner.com/addtocart.aspx?returnurl=showproduct.aspx%3fProductID%3d2688%26SEName%3dnew-testament-cricut-cartridge", False 
    '~~> Indicate that the body of the request contains form data 
    xmlhttp.setRequestHeader "Content-Type", "application/x-www-form-urlencoded" 
    '~~> Send the data as name/value pairs 
    xmlhttp.Send "Quantity=1&VariantID=2705&ProductID=2688" 

    response = xmlhttp.responseText 
    objIE.document.Write response 

    Set xmlhttp = Nothing 

End Sub 

よろしく

シド

+0

+1良いアイデアきれいresponsetextをテストするためにIEを使用します – brettdj

関連する問題