{"id":2346,"date":"2012-10-22T13:22:51","date_gmt":"2012-10-22T04:22:51","guid":{"rendered":"http:\/\/www.ka-net.org\/blog\/?p=2346"},"modified":"2013-08-19T14:12:43","modified_gmt":"2013-08-19T05:12:43","slug":"%e3%83%89%e3%83%a9%e3%83%83%e3%82%b0%e3%83%89%e3%83%ad%e3%83%83%e3%83%97%e3%81%a7excel%e3%81%ae%e3%82%a2%e3%83%89%e3%82%a4%e3%83%b3%e3%82%92%e7%99%bb%e9%8c%b2%e3%81%99%e3%82%8bvbscript","status":"publish","type":"post","link":"https:\/\/www.ka-net.org\/blog\/?p=2346","title":{"rendered":"\u30c9\u30e9\u30c3\u30b0&#038;\u30c9\u30ed\u30c3\u30d7\u3067Excel\u306e\u30a2\u30c9\u30a4\u30f3\u3092\u767b\u9332\u3059\u308bVBScript"},"content":{"rendered":"<p>\u300c<a href=\"\/\/www.ka-net.org\/other\/ot11.html\" title=\"\u30c9\u30e9\u30c3\u30b0&#038;\u30c9\u30ed\u30c3\u30d7\u3067Word\u306e\u30c6\u30f3\u30d7\u30ec\u30fc\u30c8\u3092\u767b\u9332\u30fb\u89e3\u9664\u3059\u308b(VBS)\" target=\"_blank\">\u30c9\u30e9\u30c3\u30b0&#038;\u30c9\u30ed\u30c3\u30d7\u3067Word\u306e\u30c6\u30f3\u30d7\u30ec\u30fc\u30c8\u3092\u767b\u9332\u30fb\u89e3\u9664\u3059\u308b(VBS)<\/a>\u300d\u3067Word\u30c6\u30f3\u30d7\u30ec\u30fc\u30c8\u306e\u767b\u9332\u30fb\u89e3\u9664\u3092\u88dc\u4f50\u3059\u308b\u30b9\u30af\u30ea\u30d7\u30c8\u3092\u7d39\u4ecb\u3057\u307e\u3057\u305f\u304c\u3001\u4eca\u56de\u306f\u30c9\u30e9\u30c3\u30b0&#038;\u30c9\u30ed\u30c3\u30d7\u3067Excel\u306e\u30a2\u30c9\u30a4\u30f3\u3092\u767b\u9332\u3059\u308b\u30b9\u30af\u30ea\u30d7\u30c8\u3092\u7d39\u4ecb\u3057\u307e\u3059\u3002<\/p>\n<p>\u4e0b\u8a18\u30b3\u30fc\u30c9\u306f\u3001<\/p>\n<ol type=\"1\">\n<li>Excel\u306e\u30a2\u30c9\u30a4\u30f3\u30d5\u30a9\u30eb\u30c0\u306e\u30d1\u30b9\u3092\u53d6\u5f97<\/li>\n<li>\u30c9\u30e9\u30c3\u30b0&#038;\u30c9\u30ed\u30c3\u30d7\u3055\u308c\u305f\u30a2\u30c9\u30a4\u30f3\u30d5\u30a1\u30a4\u30eb\u3092Excel\u306e\u30a2\u30c9\u30a4\u30f3\u30d5\u30a9\u30eb\u30c0\u306b\u30b3\u30d4\u30fc<\/li>\n<li>\u30b3\u30d4\u30fc\u3057\u305f\u30a2\u30c9\u30a4\u30f3\u30d5\u30a1\u30a4\u30eb\u3092\u767b\u9332<\/li>\n<\/ol>\n<p>\u3068\u3044\u3063\u305f\u4f5c\u696d\u3092\u81ea\u52d5\u7684\u306b\u884c\u3044\u307e\u3059\u3002<br \/>\n\u30a2\u30c9\u30a4\u30f3\u30d5\u30a1\u30a4\u30eb\u306e\u30b3\u30d4\u30fc\u5148\u3092\u5909\u66f4\u3057\u305f\u3044\u3001\u8907\u6570\u306e\u30a2\u30c9\u30a4\u30f3\u30d5\u30a1\u30a4\u30eb\u3092\u540c\u6642\u306b\u767b\u9332\u3057\u305f\u3044\u3001\u3068\u3044\u3063\u305f\u5834\u5408\u306b\u306f\u3001\u9069\u5f53\u306b\u30b3\u30fc\u30c9\u3092\u5909\u66f4\u3057\u3066\u3054\u4f7f\u7528\u304f\u3060\u3055\u3044\u3002<\/p>\n<pre class=\"brush: vb; title: ; notranslate\" title=\"\">Option Explicit\r\n\r\nInstallAddIn()\r\nIf MsgBox(&quot;\u51e6\u7406\u304c\u7d42\u4e86\u3057\u307e\u3057\u305f\u3002&quot; &amp; vbCrLf &amp; &quot;Excel\u3092\u4eca\u3059\u3050\u8d77\u52d5\u3057\u307e\u3059\u304b\uff1f&quot;, vbYesNo) = vbYes Then _\r\nCreateObject(&quot;WScript.Shell&quot;).Run &quot;EXCEL.EXE&quot;, 1, False\r\n\r\nPublic Sub InstallAddIn()\r\n  Dim Args\r\n  Dim SourceFilePath\r\n  Dim AddInFileName\r\n  Dim AddInFilePath\r\n  Dim AddInFolderPath\r\n  Dim Wb\r\n  Const MsgTitle = &quot;Excel\u30a2\u30c9\u30a4\u30f3\u30d5\u30a1\u30a4\u30eb\u767b\u9332\u30b9\u30af\u30ea\u30d7\u30c8&quot;\r\n  \r\n  Set Args = WScript.Arguments\r\n  If Args.Count &lt; 1 Then\r\n    MsgBox &quot;Excel\u306b\u767b\u9332\u3057\u305f\u3044\u30a2\u30c9\u30a4\u30f3\u30d5\u30a1\u30a4\u30eb\u3092&quot; &amp; vbCrLf &amp; _\r\n           &quot;\u5f53\u30b9\u30af\u30ea\u30d7\u30c8\u30d5\u30a1\u30a4\u30eb\u306b\u30c9\u30e9\u30c3\u30b0&amp;\u30c9\u30ed\u30c3\u30d7\u3057\u3066&quot; &amp; vbCrLf &amp; _\r\n           &quot;\u51e6\u7406\u3092\u5b9f\u884c\u3057\u3066\u304f\u3060\u3055\u3044\u3002&quot;, 16, MsgTitle\r\n    Exit Sub\r\n  ElseIf Args.Count &gt; 1 Then\r\n    MsgBox &quot;\u5f53\u30b9\u30af\u30ea\u30d7\u30c8\u304c\u4e00\u5ea6\u306b\u51e6\u7406\u3067\u304d\u308b\u306e\u306f1\u30d5\u30a1\u30a4\u30eb\u3060\u3051\u3067\u3059\u3002&quot; &amp; vbCrLf &amp; _\r\n           &quot;\u51e6\u7406\u3092\u4e2d\u6b62\u3057\u307e\u3059\u3002&quot;, 16, MsgTitle\r\n    Exit Sub\r\n  End If\r\n  With CreateObject(&quot;Scripting.FileSystemObject&quot;)\r\n    Select Case LCase(.GetExtensionName(Args(0)))\r\n      Case &quot;xla&quot;, &quot;xlam&quot;\r\n        AddInFileName = .GetFileName(Args(0))\r\n        SourceFilePath = Args(0)\r\n      Case Else\r\n        MsgBox &quot;Excel\u30a2\u30c9\u30a4\u30f3\u30d5\u30a1\u30a4\u30eb\u3067\u306f\u3042\u308a\u307e\u305b\u3093\u3002&quot; &amp; vbCrLf &amp; &quot;\u51e6\u7406\u3092\u4e2d\u6b62\u3057\u307e\u3059\u3002&quot;, 16, MsgTitle\r\n        Exit Sub\r\n    End Select\r\n  End With\r\n  Set Args = Nothing\r\n  \r\n  '\u30a2\u30d7\u30ea\u30b1\u30fc\u30b7\u30e7\u30f3\u8d77\u52d5\u30c1\u30a7\u30c3\u30af\r\n  If ChkApp Then\r\n    MsgBox &quot;Excel\u304c\u8d77\u52d5\u3057\u3066\u3044\u307e\u3059\u3002&quot; &amp; vbCrLf &amp; &quot;Excel\u3092\u7d42\u4e86\u3057\u3066\u304b\u3089\u518d\u5ea6\u5b9f\u884c\u3057\u3066\u304f\u3060\u3055\u3044\u3002&quot;, 16, MsgTitle\r\n    Exit Sub\r\n  End If\r\n  \r\n  '\u30a2\u30c9\u30a4\u30f3\u30d5\u30a9\u30eb\u30c0\u306e\u30d1\u30b9\u53d6\u5f97\r\n  AddInFolderPath = GetUserLibraryPath()\r\n  If Len(AddInFolderPath) &lt; 1 Then\r\n    MsgBox &quot;\u30a2\u30c9\u30a4\u30f3\u30d5\u30a9\u30eb\u30c0\u306e\u30d1\u30b9\u306e\u53d6\u5f97\u306b\u5931\u6557\u3057\u307e\u3057\u305f\u3002&quot;, 16, MsgTitle\r\n    Exit Sub\r\n  End If\r\n  If Right(AddInFolderPath, 1) &lt;&gt; &quot;\\&quot; Then AddInFolderPath = AddInFolderPath &amp; &quot;\\&quot;\r\n  AddInFilePath =  AddInFolderPath &amp; AddInFileName\r\n  \r\n  '\u30a2\u30c9\u30a4\u30f3\u30d5\u30a1\u30a4\u30eb\u306e\u30b3\u30d4\u30fc\r\n  On Error Resume Next\r\n  With CreateObject(&quot;Scripting.FileSystemObject&quot;)\r\n    If .FolderExists(AddInFolderPath) &lt;&gt; True Then\r\n      MsgBox &quot;\u30a2\u30c9\u30a4\u30f3\u30d5\u30a9\u30eb\u30c0\u304c\u898b\u3064\u304b\u308a\u307e\u305b\u3093\u3067\u3057\u305f\u3002&quot;, 16, MsgTitle\r\n      Exit Sub\r\n    End If\r\n    If .FileExists(AddInFilePath) Then\r\n      MsgBox &quot;\u3059\u3067\u306b&#x5B;&quot; &amp; AddInFilePath &amp; &quot;]\u304c\u5b58\u5728\u3057\u3066\u3044\u307e\u3059\u3002&quot; &amp; vbCrLf &amp; _\r\n             &quot;\u51e6\u7406\u3092\u4e2d\u6b62\u3057\u307e\u3059\u3002&quot;, 16, MsgTitle\r\n      Exit Sub\r\n    End If\r\n    .CopyFile SourceFilePath, AddInFolderPath, True '\u30d5\u30a1\u30a4\u30eb\u30b3\u30d4\u30fc(\u4e0a\u66f8\u304d)\r\n  End With\r\n  \r\n  '\u30a2\u30c9\u30a4\u30f3\u306e\u767b\u9332\r\n  With CreateObject(&quot;Excel.Application&quot;)\r\n    .Visible = True\r\n    Set Wb = .Workbooks.Add()\r\n    .AddIns.Add(AddInFilePath).Installed = True\r\n    Wb.Close False\r\n    .Quit\r\n  End With\r\n  If Err.Number &lt;&gt; 0 Then\r\n    MsgBox &quot;\u30a8\u30e9\u30fc\u304c\u767a\u751f\u3057\u307e\u3057\u305f\u3002&quot; &amp; vbCrLf &amp; &quot;\u30a8\u30e9\u30fc\u5185\u5bb9 : &quot; &amp; Err.Description, 16, MsgTitle\r\n    Err.Clear\r\n    Exit Sub\r\n  End If\r\n  On Error GoTo 0\r\nEnd Sub\r\n\r\n'\u30a2\u30c9\u30a4\u30f3\u30d5\u30a9\u30eb\u30c0\u306e\u30d1\u30b9\u53d6\u5f97\r\nPrivate Function GetUserLibraryPath()\r\n  Dim ret\r\n  \r\n  ret = &quot;&quot; '\u521d\u671f\u5316\r\n  On Error Resume Next\r\n  With CreateObject(&quot;Excel.Application&quot;)\r\n    .Visible = False\r\n    ret = .UserLibraryPath\r\n    .Quit\r\n  End With\r\n  Err.Clear\r\n  On Error GoTo 0\r\n  GetUserLibraryPath = ret\r\nEnd Function\r\n\r\n'Excel\u306e\u8d77\u52d5\u30c1\u30a7\u30c3\u30af\r\nPrivate Function ChkApp()\r\n  Dim app, ret\r\n  \r\n  ret = False '\u521d\u671f\u5316\r\n  On Error Resume Next\r\n  Set app = GetObject(, &quot;Excel.Application&quot;)\r\n  Err.Clear\r\n  On Error GoTo 0\r\n  If Not IsEmpty(app) Then ret = True\r\n  ChkApp = ret\r\nEnd Function<\/pre>\n<h4>\u25a0 \u4f7f\u3044\u65b9<\/h4>\n<ol type=\"1\">\n<li>\u4e0a\u8a18\u30b3\u30fc\u30c9\u3092\u30b3\u30d4\u30fc\u3057\u3066\u30e1\u30e2\u5e33\u306b\u8cbc\u308a\u4ed8\u3051\u307e\u3059\u3002<\/li>\n<li>\u62e1\u5f35\u5b50\u3092\u300c<span style=\"color: #ff0000; font-weight: bold;\">vbs<\/span>\u300d\u306b\u3057\u3066\u4fdd\u5b58\u3057\u307e\u3059\u3002<\/li>\n<li>Excel\u3092\u7d42\u4e86\u3057\u305f\u72b6\u614b\u3067\u3001\u624b\u98062.\u3067\u4fdd\u5b58\u3057\u305fvbs\u30d5\u30a1\u30a4\u30eb\u306bExcel\u306e\u30a2\u30c9\u30a4\u30f3\u30d5\u30a1\u30a4\u30eb(<span style=\"color: #ff0000; font-weight: bold;\">xla,xlam<\/span>)\u3092\u30c9\u30e9\u30c3\u30b0&#038;\u30c9\u30ed\u30c3\u30d7\u3057\u307e\u3059\u3002<\/li>\n<\/ol>\n","protected":false},"excerpt":{"rendered":"\u300c\u30c9\u30e9\u30c3\u30b0&#038;\u30c9\u30ed\u30c3\u30d7\u3067Word\u306e\u30c6\u30f3\u30d7\u30ec\u30fc\u30c8\u3092\u767b\u9332\u30fb\u89e3\u9664\u3059\u308b(VBS)\u300d\u3067Word\u30c6\u30f3\u30d7\u30ec\u30fc\u30c8\u306e\u767b\u9332\u30fb\u89e3\u9664\u3092\u88dc\u4f50\u3059\u308b\u30b9\u30af\u30ea\u30d7\u30c8\u3092\u7d39\u4ecb\u3057\u307e\u3057\u305f\u304c\u3001\u4eca\u56de\u306f\u30c9\u30e9\u30c3\u30b0&#038;\u30c9\u30ed\u30c3\u30d7\u3067Excel\u306e\u30a2\u30c9\u30a4\u30f3\u3092\u767b\u9332\u3059\u308b [&hellip;]","protected":false},"author":1,"featured_media":7111,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_jetpack_memberships_contains_paid_content":false,"footnotes":"","jetpack_publicize_message":"","jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":false,"jetpack_social_options":{"image_generator_settings":{"template":"highway","default_image_id":0,"font":"","enabled":false},"version":2}},"categories":[48,4,6],"tags":[46,139],"class_list":["post-2346","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-excel-office","category-office","category-vbs","tag-excel","tag-vbs"],"aioseo_notices":[],"jetpack_publicize_connections":[],"jetpack_featured_media_url":"https:\/\/www.ka-net.org\/blog\/wp-content\/uploads\/eyecatch-Excel.png","jetpack_shortlink":"https:\/\/wp.me\/p4UZZr-BQ","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/www.ka-net.org\/blog\/index.php?rest_route=\/wp\/v2\/posts\/2346","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.ka-net.org\/blog\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.ka-net.org\/blog\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.ka-net.org\/blog\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.ka-net.org\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=2346"}],"version-history":[{"count":4,"href":"https:\/\/www.ka-net.org\/blog\/index.php?rest_route=\/wp\/v2\/posts\/2346\/revisions"}],"predecessor-version":[{"id":3438,"href":"https:\/\/www.ka-net.org\/blog\/index.php?rest_route=\/wp\/v2\/posts\/2346\/revisions\/3438"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.ka-net.org\/blog\/index.php?rest_route=\/wp\/v2\/media\/7111"}],"wp:attachment":[{"href":"https:\/\/www.ka-net.org\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=2346"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.ka-net.org\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=2346"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.ka-net.org\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=2346"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}