{"id":633,"date":"2025-05-09T21:46:59","date_gmt":"2025-05-09T13:46:59","guid":{"rendered":"https:\/\/www.jumoon.top\/?p=633"},"modified":"2026-01-08T22:58:36","modified_gmt":"2026-01-08T14:58:36","slug":"%e9%92%89%e9%92%89%e5%bc%80%e5%8f%91%e7%bb%93%e5%90%88excelvba%e5%ae%9e%e7%8e%b0%e6%89%b9%e9%87%8f%e6%8e%a8%e9%80%81%e4%bf%a1%e6%81%af","status":"publish","type":"post","link":"https:\/\/www.jumoon.top\/?p=633","title":{"rendered":"\u9489\u9489\u5f00\u53d1\u7ed3\u5408ExcelVBA\u5b9e\u73b0\u6279\u91cf\u63a8\u9001\u4fe1\u606f"},"content":{"rendered":"\n<p>\u57fa\u4e8e\u9489\u9489\u5f00\u653e\u5e73\u53f0\uff0c\u521b\u5efa\u5e94\u7528\uff0c\u6388\u6743\u6210\u5458\u4fe1\u606f\u8bfb\u6743\u9650\uff0c\u8c03\u7528\u4f01\u4e1aAPI\u57fa\u7840\u6743\u9650\uff0c\u901a\u8fc7Excel VBA\u8c03\u7528api\u63a5\u53e3\u5b9e\u73b0\u4f01\u4e1a\u5185\u90e8\u6279\u91cf\u63a8\u9001\u4fe1\u606f\u3002\u4ee3\u7801\u57fa\u4e8e\u5f53\u524d\u5de5\u4f5c\u8868\u7684a\u5217\u548cb\u5217\u4e2d\u7684\u6570\u636e\u53d1\u8d77\u63a8\u9001\uff0c\u5e76\u56de\u5199\u63a8\u9001\u7ed3\u679c\u5230c\u5217\uff0c\u5176\u4e2da\u5217\u662fuserid\uff0cb\u5217\u662f\u8981\u63a8\u9001\u7684\u5185\u5bb9\uff0c\u7b2c\u4e00\u884c\u4e3a\u6807\u9898\u884c\u3002<\/p>\n\n\n\n<p>\u9700\u8981\u6ce8\u610f\u7684\u5730\u65b9\uff1a\u9664\u4e86\u793a\u4f8b\u4ee3\u7801\u5916\u8fd9\u91cc\u9700\u8981\u5f15\u7528\u4e00\u4e2aJSON\u89e3\u6790\u5668\uff0c\u8fd9\u91cc\u76f4\u63a5\u63d0\u4f9b\u9644\u4ef6\uff0c\u9700\u8981\u624b\u5de5\u5f15\u5165\u5230VBA\u9879\u76ee\u3002\u9664\u6b64\u4e4b\u5916\u8fd8\u9700\u8981\u5728 VBA \u7f16\u8f91\u5668\u4e2d\u70b9\u51fb&#8221;\u5de5\u5177&#8221; &gt; &#8220;\u5f15\u7528&#8221;\uff0c\u52fe\u9009&#8221;Microsoft Scripting Runtime&#8221;\u3002<\/p>\n\n\n\n<div class=\"wp-block-file aligncenter\"><a id=\"wp-block-file--media-e2cf2d13-cf98-4a3a-838d-c0914a1c107e\" href=\"https:\/\/www.jumoon.top\/wp-content\/uploads\/2025\/05\/JsonConverter.rar\">JsonConverter<\/a><a href=\"https:\/\/www.jumoon.top\/wp-content\/uploads\/2025\/05\/JsonConverter.rar\" class=\"wp-block-file__button wp-element-button\" download aria-describedby=\"wp-block-file--media-e2cf2d13-cf98-4a3a-838d-c0914a1c107e\">\u4e0b\u8f7d<\/a><\/div>\n\n\n\n<p class=\"has-text-align-center\">\u6267\u884c\u7ed3\u679c\u6f14\u793a\uff0c\u5de6\u8fb9\u662fexcel\u8868\uff0c\u53f3\u8fb9\u662f\u9489\u9489\u6536\u5230\u7684\u5de5\u4f5c\u901a\u77e5\u3002<\/p>\n\n\n\n<figure class=\"wp-block-image aligncenter size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"505\" src=\"https:\/\/www.jumoon.top\/wp-content\/uploads\/2025\/05\/excel\u63a8\u90011-1024x505.png\" alt=\"\" class=\"wp-image-635\" srcset=\"https:\/\/www.jumoon.top\/wp-content\/uploads\/2025\/05\/excel\u63a8\u90011-1024x505.png 1024w, https:\/\/www.jumoon.top\/wp-content\/uploads\/2025\/05\/excel\u63a8\u90011-300x148.png 300w, https:\/\/www.jumoon.top\/wp-content\/uploads\/2025\/05\/excel\u63a8\u90011-768x379.png 768w, https:\/\/www.jumoon.top\/wp-content\/uploads\/2025\/05\/excel\u63a8\u90011.png 1203w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<p class=\"has-text-align-center\">\u4ee5\u4e0b\u662f\u793a\u4f8b\u4ee3\u7801\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>Option Explicit\n\n' \u9489\u9489\u914d\u7f6e\uff08\u66ff\u6362\u4e3a\u4f60\u81ea\u5df1\u7684\u503c\uff09\nPrivate Const APP_KEY As String = \"\u4f60\u7684AppKey\"\nPrivate Const APP_SECRET As String = \"\u4f60\u7684AppSecret\"\nPrivate Const AGENT_ID As String = \"\u4f60\u7684AgentId\" \n\nPrivate Function GetAccessToken() As String\n    Dim url As String\n    Dim http As Object\n    Dim response As String\n    Dim json As Object\n    \n    On Error GoTo ErrorHandler\n    \n    Set http = CreateObject(\"MSXML2.XMLHTTP\")\n    url = \"https:\/\/oapi.dingtalk.com\/gettoken?appkey=\" &amp; APP_KEY &amp; \"&amp;appsecret=\" &amp; APP_SECRET\n    \n    With http\n        .Open \"GET\", url, False\n        .send\n        response = .responseText\n    End With\n    \n    Set json = ParseJson(response)\n    \n    If json.Exists(\"access_token\") Then\n        GetAccessToken = json(\"access_token\")\n    Else\n        MsgBox \"\u83b7\u53d6access_token\u5931\u8d25: \" &amp; response, vbExclamation\n        GetAccessToken = \"\"\n    End If\n    \n    Exit Function\n    \nErrorHandler:\n    MsgBox \"\u83b7\u53d6access_token\u65f6\u51fa\u9519: \" &amp; Err.Description, vbExclamation\n    GetAccessToken = \"\"\nEnd Function\n\nPrivate Function SendDingTalkMessage(userid As String, content As String, token As String) As String\n    Dim url As String\n    Dim http As Object\n    Dim requestBody As String\n    Dim response As String\n    \n    On Error GoTo ErrorHandler\n    \n    Set http = CreateObject(\"MSXML2.XMLHTTP\")\n    url = \"https:\/\/oapi.dingtalk.com\/topapi\/message\/corpconversation\/asyncsend_v2?access_token=\" &amp; token\n    \n    requestBody = \"{\"\n    requestBody = requestBody &amp; \"\"\"agent_id\"\": \"\"\" &amp; AGENT_ID &amp; \"\"\",\"\n    requestBody = requestBody &amp; \"\"\"userid_list\"\": \"\"\" &amp; userid &amp; \"\"\",\"\n    requestBody = requestBody &amp; \"\"\"msg\"\": {\"\n    requestBody = requestBody &amp; \"\"\"msgtype\"\": \"\"text\"\",\"\n    requestBody = requestBody &amp; \"\"\"text\"\": {\"\"content\"\": \"\"\" &amp; content &amp; \"\"\"}\"\n    requestBody = requestBody &amp; \"}\"\n    requestBody = requestBody &amp; \"}\"\n    \n    With http\n        .Open \"POST\", url, False\n        .setRequestHeader \"Content-Type\", \"application\/json\"\n        .send requestBody\n        response = .responseText\n    End With\n    \n    SendDingTalkMessage = response\n    Exit Function\n    \nErrorHandler:\n    MsgBox \"\u53d1\u9001\u6d88\u606f\u65f6\u51fa\u9519: \" &amp; Err.Description, vbExclamation\n    SendDingTalkMessage = \"{\"\"errcode\"\": -1, \"\"errmsg\"\": \"\"\" &amp; Err.Description &amp; \"\"\"}\"\nEnd Function\n\nPublic Sub PushFromExcel()\n    Dim ws As Worksheet\n    Dim lastRow As Long\n    Dim i As Long\n    Dim userid As String\n    Dim content As String\n    Dim token As String\n    Dim result As String\n    \n    On Error GoTo ErrorHandler\n    \n    Application.ScreenUpdating = False\n    Application.DisplayAlerts = False\n    \n    Set ws = ActiveSheet\n    \n    lastRow = ws.Cells(ws.Rows.Count, \"A\").End(xlUp).Row\n    \n    token = GetAccessToken()\n    If token = \"\" Then Exit Sub\n    \n    For i = 2 To lastRow\n        userid = CStr(ws.Cells(i, 1).Value)\n        content = CStr(ws.Cells(i, 2).Value)\n        \n        If content = \"\" Then content = \"\uff08\u7a7a\u5185\u5bb9\uff09\"\n        \n        Debug.Print \"\u51c6\u5907\u63a8\u9001 -&gt; UserID: '\" &amp; userid &amp; \"', \u5185\u5bb9: '\" &amp; content &amp; \"'\"\n        \n        result = SendDingTalkMessage(userid, content, token)\n        ws.Cells(i, 3).Value = result\n        \n        Application.Wait Now + TimeValue(\"00:00:01\")\n    Next i\n    \n    MsgBox \"\u5904\u7406\u5b8c\u6210\uff01\u5171\u63a8\u9001 \" &amp; lastRow - 1 &amp; \" \u6761\u6d88\u606f\u3002\", vbInformation\n    \n    Exit Sub\n    \nErrorHandler:\n    Application.ScreenUpdating = True\n    Application.DisplayAlerts = True\n    MsgBox \"\u5904\u7406\u8fc7\u7a0b\u4e2d\u51fa\u9519: \" &amp; Err.Description, vbExclamation\nEnd Sub\n\nPrivate Function ParseJson(ByVal JsonString As String) As Object\n    Set ParseJson = JsonConverter.ParseJson(JsonString)\nEnd Function\n\n<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>\u57fa\u4e8e\u9489\u9489\u5f00\u653e\u5e73\u53f0\uff0c\u521b\u5efa\u5e94\u7528\uff0c\u6388\u6743\u6210\u5458\u4fe1\u606f\u8bfb\u6743\u9650\uff0c\u8c03\u7528\u4f01\u4e1aAPI\u57fa\u7840\u6743\u9650\uff0c\u901a\u8fc7Excel VBA\u8c03\u7528api\u63a5\u53e3\u5b9e [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"site-container-style":"default","site-container-layout":"default","site-sidebar-layout":"default","site-transparent-header":"default","disable-article-header":"default","disable-site-header":"default","disable-site-footer":"default","disable-content-area-spacing":"default","footnotes":""},"categories":[19],"tags":[],"class_list":["post-633","post","type-post","status-publish","format-standard","hentry","category-19"],"_links":{"self":[{"href":"https:\/\/www.jumoon.top\/index.php?rest_route=\/wp\/v2\/posts\/633","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.jumoon.top\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.jumoon.top\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.jumoon.top\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.jumoon.top\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=633"}],"version-history":[{"count":1,"href":"https:\/\/www.jumoon.top\/index.php?rest_route=\/wp\/v2\/posts\/633\/revisions"}],"predecessor-version":[{"id":986,"href":"https:\/\/www.jumoon.top\/index.php?rest_route=\/wp\/v2\/posts\/633\/revisions\/986"}],"wp:attachment":[{"href":"https:\/\/www.jumoon.top\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=633"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.jumoon.top\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=633"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.jumoon.top\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=633"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}