{"id":400,"date":"2025-01-08T02:33:35","date_gmt":"2025-01-07T17:33:35","guid":{"rendered":"https:\/\/hajidai.com\/excel\/2025\/01\/excel%e4%b8%8a%e7%b4%9a%e8%80%85%e5%bf%85%e8%a6%8b%ef%bc%81%e6%a5%ad%e5%8b%99%e5%8a%b9%e7%8e%87%e3%82%92%e5%8a%87%e7%9a%84%e3%81%ab%e4%b8%8a%e3%81%92%e3%82%8b%e5%a4%96%e9%83%a8%e3%82%b7%e3%82%b9\/"},"modified":"2025-01-08T02:33:35","modified_gmt":"2025-01-07T17:33:35","slug":"excel%e4%b8%8a%e7%b4%9a%e8%80%85%e5%bf%85%e8%a6%8b%ef%bc%81%e6%a5%ad%e5%8b%99%e5%8a%b9%e7%8e%87%e3%82%92%e5%8a%87%e7%9a%84%e3%81%ab%e4%b8%8a%e3%81%92%e3%82%8b%e5%a4%96%e9%83%a8%e3%82%b7%e3%82%b9","status":"publish","type":"post","link":"https:\/\/hajidai.com\/excel\/2025\/01\/excel%e4%b8%8a%e7%b4%9a%e8%80%85%e5%bf%85%e8%a6%8b%ef%bc%81%e6%a5%ad%e5%8b%99%e5%8a%b9%e7%8e%87%e3%82%92%e5%8a%87%e7%9a%84%e3%81%ab%e4%b8%8a%e3%81%92%e3%82%8b%e5%a4%96%e9%83%a8%e3%82%b7%e3%82%b9\/","title":{"rendered":"Excel\u4e0a\u7d1a\u8005\u5fc5\u898b\uff01\u696d\u52d9\u52b9\u7387\u3092\u5287\u7684\u306b\u4e0a\u3052\u308b\u5916\u90e8\u30b7\u30b9\u30c6\u30e0\u9023\u643a\u30de\u30af\u30ed3\u9078"},"content":{"rendered":"<h2>Excel\u4e0a\u7d1a\u8005\u304c\u77e5\u3063\u3066\u304a\u304f\u3079\u304d\u9ad8\u5ea6\u306a\u5916\u90e8\u30b7\u30b9\u30c6\u30e0\u9023\u643a\u30de\u30af\u30ed<\/h2>\n<p>Excel\u3092\u4f7f\u3044\u3053\u306a\u3057\u3066\u3082\u3063\u3068\u697d\u3092\u3057\u305f\u3044\u3001\u696d\u52d9\u3092\u52b9\u7387\u5316\u3057\u305f\u3044\u4e0a\u7d1a\u8005\u306e\u65b9\u3005\u306b\u5411\u3051\u3066\u3001\u3059\u3050\u306b\u8a66\u305b\u308b\u30de\u30af\u30ed\u30b3\u30fc\u30c9\u3092\u3054\u7d39\u4ecb\u3057\u307e\u3059\u3002<\/p>\n<p>&#8220;`vba<br \/>\nSub ConnectToExternalDatabase()<br \/>\n    Dim conn As ADODB.Connection<br \/>\n    Dim rs As ADODB.Recordset<br \/>\n    Dim sql As String<\/p>\n<p>    Set conn = New ADODB.Connection<br \/>\n    conn.Open &#8220;Provider=SQLOLEDB;Data Source=ServerName;Initial Catalog=DatabaseName;User ID=Username;Password=Password;&#8221;<\/p>\n<p>    sql = &#8220;SELECT * FROM TableName&#8221;<br \/>\n    Set rs = conn.Execute(sql)<\/p>\n<p>    Sheets(&#8220;Sheet1&#8221;).Range(&#8220;A1&#8221;).CopyFromRecordset rs<\/p>\n<p>    rs.Close<br \/>\n    conn.Close<br \/>\n    Set rs = Nothing<br \/>\n    Set conn = Nothing<br \/>\nEnd Sub<br \/>\n&#8220;`<\/p>\n<p>\u3053\u306e\u30de\u30af\u30ed\u306f\u3001\u5916\u90e8\u306e\u30c7\u30fc\u30bf\u30d9\u30fc\u30b9\u306b\u63a5\u7d9a\u3057\u3066\u30c7\u30fc\u30bf\u3092\u53d6\u5f97\u3057\u3001Excel\u30b7\u30fc\u30c8\u306b\u8cbc\u308a\u4ed8\u3051\u308b\u3082\u306e\u3067\u3059\u3002<\/p>\n<h3>1. \u30c7\u30fc\u30bf\u30d9\u30fc\u30b9\u9023\u643a\u306e\u91cd\u8981\u6027<\/h3>\n<p>Excel \u30de\u30af\u30ed\u3092\u6d3b\u7528\u3057\u305f\u5916\u90e8\u30b7\u30b9\u30c6\u30e0\u9023\u643a\u306f\u3001\u696d\u52d9\u52b9\u7387\u5316\u306e\u8981\u3067\u3059\u3002\u591a\u304f\u306e\u4f01\u696d\u3067\u306f\u3001\u69d8\u3005\u306a\u30b7\u30b9\u30c6\u30e0\u3084\u30c7\u30fc\u30bf\u30d9\u30fc\u30b9\u304c\u5b58\u5728\u3057\u307e\u3059\u304c\u3001\u305d\u308c\u3089\u3092\u7d71\u5408\u7684\u306b\u6271\u3046\u3053\u3068\u304c\u96e3\u3057\u3044\u5834\u5408\u304c\u3042\u308a\u307e\u3059\u3002Excel\u306f\u3001\u3053\u308c\u3089\u306e\u7570\u306a\u308b\u30b7\u30b9\u30c6\u30e0\u9593\u306e\u30d6\u30ea\u30c3\u30b8\u3068\u3057\u3066\u6a5f\u80fd\u3057\u3001\u30c7\u30fc\u30bf\u306e\u7d71\u5408\u3084\u5206\u6790\u3092\u5bb9\u6613\u306b\u3057\u307e\u3059\u3002<\/p>\n<p>\u4f8b\u3048\u3070\u3001\u55b6\u696d\u30c7\u30fc\u30bf\u30d9\u30fc\u30b9\u3001\u5728\u5eab\u7ba1\u7406\u30b7\u30b9\u30c6\u30e0\u3001\u4f1a\u8a08\u30b7\u30b9\u30c6\u30e0\u306a\u3069\u3001\u8907\u6570\u306e\u30bd\u30fc\u30b9\u304b\u3089\u30c7\u30fc\u30bf\u3092\u53d6\u5f97\u3057\u3001Excel\u3067\u4e00\u5143\u7ba1\u7406\u3059\u308b\u3053\u3068\u304c\u3067\u304d\u307e\u3059\u3002\u3053\u308c\u306b\u3088\u308a\u3001\u6a2a\u65ad\u7684\u306a\u5206\u6790\u3084\u5831\u544a\u66f8\u306e\u4f5c\u6210\u304c\u683c\u6bb5\u306b\u52b9\u7387\u5316\u3055\u308c\u307e\u3059\u3002<\/p>\n<h3>2. API\u3092\u6d3b\u7528\u3057\u305f\u30ea\u30a2\u30eb\u30bf\u30a4\u30e0\u30c7\u30fc\u30bf\u53d6\u5f97<\/h3>\n<p>\u6700\u8fd1\u306e\u30c8\u30ec\u30f3\u30c9\u3068\u3057\u3066\u3001API\u3092\u4f7f\u7528\u3057\u305f\u30ea\u30a2\u30eb\u30bf\u30a4\u30e0\u30c7\u30fc\u30bf\u306e\u53d6\u5f97\u304c\u3042\u308a\u307e\u3059\u3002Excel \u30de\u30af\u30ed\u3092\u4f7f\u7528\u3057\u3066\u3001\u30a6\u30a7\u30d6API\u306b\u30a2\u30af\u30bb\u30b9\u3057\u3001\u6700\u65b0\u306e\u60c5\u5831\u3092\u81ea\u52d5\u7684\u306b\u53d6\u5f97\u3059\u308b\u3053\u3068\u304c\u53ef\u80fd\u3067\u3059\u3002<\/p>\n<p>\u4f8b\u3048\u3070\u3001\u682a\u4fa1\u30c7\u30fc\u30bf\u3001\u70ba\u66ff\u30ec\u30fc\u30c8\u3001\u6c17\u8c61\u60c5\u5831\u306a\u3069\u3092\u30ea\u30a2\u30eb\u30bf\u30a4\u30e0\u3067\u53d6\u5f97\u3057\u3001Excel\u30b7\u30fc\u30c8\u4e0a\u3067\u81ea\u52d5\u66f4\u65b0\u3059\u308b\u3053\u3068\u304c\u3067\u304d\u307e\u3059\u3002\u3053\u308c\u306b\u3088\u308a\u3001\u5e38\u306b\u6700\u65b0\u306e\u30c7\u30fc\u30bf\u306b\u57fa\u3065\u3044\u305f\u5206\u6790\u3084\u610f\u601d\u6c7a\u5b9a\u304c\u53ef\u80fd\u306b\u306a\u308a\u307e\u3059\u3002<\/p>\n<p>\u4ee5\u4e0b\u306f\u3001WebAPI\u304b\u3089\u30c7\u30fc\u30bf\u3092\u53d6\u5f97\u3059\u308b\u7c21\u5358\u306a\u30de\u30af\u30ed\u306e\u4f8b\u3067\u3059\uff1a<\/p>\n<p>&#8220;`vba<br \/>\nSub GetDataFromAPI()<br \/>\n    Dim xhr As Object<br \/>\n    Set xhr = CreateObject(&#8220;MSXML2.XMLHTTP&#8221;)<\/p>\n<p>    xhr.Open &#8220;GET&#8221;, &#8220;https:\/\/api.example.com\/data&#8221;, False<br \/>\n    xhr.Send<\/p>\n<p>    If xhr.Status = 200 Then<br \/>\n        Sheets(&#8220;Sheet1&#8221;).Range(&#8220;A1&#8221;).Value = xhr.responseText<br \/>\n    Else<br \/>\n        MsgBox &#8220;Error: &#8221; &#038; xhr.Status &#038; &#8221; &#8211; &#8221; &#038; xhr.statusText<br \/>\n    End If<br \/>\nEnd Sub<br \/>\n&#8220;`<\/p>\n<h3>3. \u30bb\u30ad\u30e5\u30ea\u30c6\u30a3\u3068\u30a8\u30e9\u30fc\u30cf\u30f3\u30c9\u30ea\u30f3\u30b0<\/h3>\n<p>\u5916\u90e8\u30b7\u30b9\u30c6\u30e0\u3068\u9023\u643a\u3059\u308b\u969b\u3001\u30bb\u30ad\u30e5\u30ea\u30c6\u30a3\u3068\u30a8\u30e9\u30fc\u30cf\u30f3\u30c9\u30ea\u30f3\u30b0\u306f\u975e\u5e38\u306b\u91cd\u8981\u3067\u3059\u3002\u30bb\u30f3\u30b7\u30c6\u30a3\u30d6\u306a\u30c7\u30fc\u30bf\u3092\u6271\u3046\u5834\u5408\u3001\u9069\u5207\u306a\u8a8d\u8a3c\u3068\u30c7\u30fc\u30bf\u306e\u6697\u53f7\u5316\u304c\u5fc5\u8981\u3067\u3059\u3002\u307e\u305f\u3001\u30cd\u30c3\u30c8\u30ef\u30fc\u30af\u306e\u554f\u984c\u3084\u4e88\u671f\u305b\u306c\u30a8\u30e9\u30fc\u306b\u5bfe\u51e6\u3059\u308b\u305f\u3081\u3001\u5805\u7262\u306a\u30a8\u30e9\u30fc\u30cf\u30f3\u30c9\u30ea\u30f3\u30b0\u3082\u6b20\u304b\u305b\u307e\u305b\u3093\u3002<\/p>\n<p>Excel \u30de\u30af\u30ed\u3067\u306f\u3001Try-Catch\u69cb\u6587\u306b\u76f8\u5f53\u3059\u308b\u6a5f\u80fd\u306f\u3042\u308a\u307e\u305b\u3093\u304c\u3001On Error\u6587\u3092\u4f7f\u7528\u3057\u3066\u30a8\u30e9\u30fc\u51e6\u7406\u3092\u5b9f\u88c5\u3067\u304d\u307e\u3059\u3002\u4ee5\u4e0b\u306f\u3001\u30a8\u30e9\u30fc\u30cf\u30f3\u30c9\u30ea\u30f3\u30b0\u3092\u542b\u3080\u30de\u30af\u30ed\u306e\u4f8b\u3067\u3059\uff1a<\/p>\n<p>&#8220;`vba<br \/>\nSub SafeDatabaseConnection()<br \/>\n    On Error GoTo ErrorHandler<\/p>\n<p>    &#8216; \u30c7\u30fc\u30bf\u30d9\u30fc\u30b9\u63a5\u7d9a\u3068\u30c7\u30fc\u30bf\u53d6\u5f97\u306e\u30b3\u30fc\u30c9<\/p>\n<p>    Exit Sub<\/p>\n<p>ErrorHandler:<br \/>\n    MsgBox &#8220;\u30a8\u30e9\u30fc\u304c\u767a\u751f\u3057\u307e\u3057\u305f: &#8221; &#038; Err.Description<br \/>\n    &#8216; \u30a8\u30e9\u30fc\u30ed\u30b0\u306e\u8a18\u9332\u3084\u30af\u30ea\u30fc\u30f3\u30a2\u30c3\u30d7\u51e6\u7406\u3092\u3053\u3053\u306b\u8a18\u8ff0<br \/>\nEnd Sub<br \/>\n&#8220;`<\/p>\n<p>\u3053\u306e\u3088\u3046\u306a\u5bfe\u7b56\u306b\u3088\u308a\u3001\u5916\u90e8\u30b7\u30b9\u30c6\u30e0\u9023\u643a\u306e\u4fe1\u983c\u6027\u3068\u5b89\u5168\u6027\u304c\u5411\u4e0a\u3057\u307e\u3059\u3002<\/p>\n<p>Excel \u30de\u30af\u30ed\u3092\u6d3b\u7528\u3057\u305f\u5916\u90e8\u30b7\u30b9\u30c6\u30e0\u9023\u643a\u306f\u3001\u30c7\u30fc\u30bf\u7d71\u5408\u3001\u30ea\u30a2\u30eb\u30bf\u30a4\u30e0\u60c5\u5831\u53d6\u5f97\u3001\u305d\u3057\u3066\u9ad8\u5ea6\u306a\u81ea\u52d5\u5316\u3092\u5b9f\u73fe\u3059\u308b\u5f37\u529b\u306a\u30c4\u30fc\u30eb\u3067\u3059\u3002\u9069\u5207\u306b\u5b9f\u88c5\u3059\u308b\u3053\u3068\u3067\u3001\u696d\u52d9\u30d7\u30ed\u30bb\u30b9\u306e\u5927\u5e45\u306a\u52b9\u7387\u5316\u3068\u3001\u30c7\u30fc\u30bf\u99c6\u52d5\u578b\u306e\u610f\u601d\u6c7a\u5b9a\u304c\u53ef\u80fd\u306b\u306a\u308a\u307e\u3059\u3002\u305f\u3060\u3057\u3001\u30bb\u30ad\u30e5\u30ea\u30c6\u30a3\u3068\u30a8\u30e9\u30fc\u51e6\u7406\u306b\u306f\u5341\u5206\u306a\u6ce8\u610f\u3092\u6255\u3044\u3001\u5e38\u306b\u6700\u65b0\u306e\u30d9\u30b9\u30c8\u30d7\u30e9\u30af\u30c6\u30a3\u30b9\u306b\u5f93\u3046\u3053\u3068\u304c\u91cd\u8981\u3067\u3059\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Excel\u4e0a\u7d1a\u8005\u304c\u77e5\u3063\u3066\u304a\u304f\u3079\u304d\u9ad8\u5ea6\u306a\u5916\u90e8\u30b7\u30b9\u30c6\u30e0\u9023\u643a\u30de\u30af\u30ed Excel\u3092\u4f7f\u3044\u3053\u306a\u3057\u3066\u3082\u3063\u3068\u697d\u3092\u3057\u305f\u3044\u3001\u696d\u52d9\u3092\u52b9\u7387\u5316\u3057\u305f\u3044\u4e0a\u7d1a\u8005\u306e\u65b9\u3005\u306b\u5411\u3051\u3066\u3001\u3059\u3050\u306b\u8a66\u305b\u308b\u30de\u30af\u30ed\u30b3\u30fc\u30c9\u3092\u3054\u7d39\u4ecb\u3057\u307e\u3059\u3002 #8220;`vba Sub C<\/p>\n","protected":false},"author":2,"featured_media":399,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_monsterinsights_skip_tracking":false,"_monsterinsights_sitenote_active":false,"_monsterinsights_sitenote_note":"","_monsterinsights_sitenote_category":0,"footnotes":""},"categories":[5],"tags":[],"class_list":["post-400","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-advanced"],"_links":{"self":[{"href":"https:\/\/hajidai.com\/excel\/wp-json\/wp\/v2\/posts\/400","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/hajidai.com\/excel\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/hajidai.com\/excel\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/hajidai.com\/excel\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/hajidai.com\/excel\/wp-json\/wp\/v2\/comments?post=400"}],"version-history":[{"count":0,"href":"https:\/\/hajidai.com\/excel\/wp-json\/wp\/v2\/posts\/400\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/hajidai.com\/excel\/wp-json\/wp\/v2\/media\/399"}],"wp:attachment":[{"href":"https:\/\/hajidai.com\/excel\/wp-json\/wp\/v2\/media?parent=400"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/hajidai.com\/excel\/wp-json\/wp\/v2\/categories?post=400"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/hajidai.com\/excel\/wp-json\/wp\/v2\/tags?post=400"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}