How to write to a “Google Spreadsheet” from Excel 2003 VBA

前端 未结 4 541
旧时难觅i
旧时难觅i 2020-12-05 08:59

I Have an Excel 2003 file with a line similar to this:

\"enter

<
4条回答
  •  陌清茗
    陌清茗 (楼主)
    2020-12-05 09:30

    I had started answering your question, but realized that it was much less trivial than I thought it was when I started playing with the OAuth 2.0 API. I think it would be a lot easier if you could make your Google spreadsheet public, but I doubt that is advisable with sales data.

    The reason this is non-trivial is the authentication part. The ASP OAuth below is probably usable with some work, but I noticed it uses Session variables and some other ASP objects, so you'd have to do a lot of tweaking.

    In that light, here is my original answer, if it helps.

    There is a google spreadsheet API: https://developers.google.com/google-apps/spreadsheets/#adding_a_list_row

    The OAuth 2.0 link that the spreadsheet docs refer to is out-of-date. You can play with the OAuth requests here, which should help you get started.

    API functions are called by GET/POST requests with XML, which you can call using the XMLHTTP object.

    First, reference Microsoft XML in your Excel project (Tools->References->Microsoft XML, v6.0)

    In your VBA, you essentially use the following to send XML requests:

    Dim x as MSXML2.XMLHTTP
    Set x = New MSXML2.XMLHTTP
    x.Open "POST", "http://example.com/", False
    x.Send ""
    

    You should be able to adapt this OAuth 2.0 ASP library for your VBA code.

    This is an ASP example of how to use that OAuth library; again since both the ASP and the VBA are using the VBScript syntax, it could probably be adapted.

提交回复
热议问题