0
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

VBAからREST APIをコールする

Posted at

はじめに

以前、VBAからAWS AuroraにMySQLドライバから接続するという記事を書いたのですが、実際に現場でやろうとしたらMySQLドライバ入れるのにVisualStudioの依存関係があり、先方からドライバ入れたくないと言われてしまった。(めんどー、VSぐらいいれてよ。)

ということで、クライアントに依存しない形で通信するためにREST APIでの通信方式を調べたのメモしておく。

コード

使うライブラリとメソッドは以下。
Set httpReq = CreateObject("MSXML2.XMLHTTP") httpReq.Open "GET", URL, False httpReq.Send


Sub apicall(var_int) 'var_intが引数として渡ってくる。

    '変数宣言
    Dim httpReq As Object
    Dim URL As Variant
    'リクエストセット
    Set httpReq = CreateObject("MSXML2.XMLHTTP")
    'GETでURLセット
    URL = "http://xxx.com/api.php?id=" & var_int
    httpReq.Open "GET", URL, False
    'リクエスト
    httpReq.Send
    Set httpReq = Nothing
     
End Sub

おわりに

今回はIaasサーバにphp配置して、そこからDBへのインサート処理を行いました。SELECTとかだと使い勝手がわるいかもですが、参照画面ぐらいならつくってもいいかもですね。

それではご査収ください~

0
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?