{"id":7605,"date":"2016-11-01T13:52:48","date_gmt":"2016-11-01T04:52:48","guid":{"rendered":"https:\/\/www.ka-net.org\/blog\/?p=7605"},"modified":"2017-03-08T00:14:53","modified_gmt":"2017-03-07T15:14:53","slug":"zip%e5%bd%a2%e5%bc%8f%e3%81%a7%e5%9c%a7%e7%b8%ae%e3%83%bb%e8%a7%a3%e5%87%8d%e3%82%92%e8%a1%8c%e3%81%86vba%e3%83%9e%e3%82%af%e3%83%ad","status":"publish","type":"post","link":"https:\/\/www.ka-net.org\/blog\/?p=7605","title":{"rendered":"ZIP\u5f62\u5f0f\u3067\u5727\u7e2e\u30fb\u89e3\u51cd\u3092\u884c\u3046VBA\u30de\u30af\u30ed"},"content":{"rendered":"<p><a href=\"https:\/\/www.ka-net.org\/blog\/?p=7240\" title=\"Office\u30d5\u30a1\u30a4\u30eb\u304b\u3089\u4f5c\u6210\u8005\u306a\u3069\u306e\u30d7\u30ed\u30d1\u30c6\u30a3\u3092\u53d6\u5f97\u3059\u308bVBScript | \u521d\u5fc3\u8005\u5099\u5fd8\u9332\" target=\"_blank\">\u3053\u306e\u8a18\u4e8b<\/a>\u306e\u3088\u3046\u306b\u3001\u51e6\u7406\u306e\u4e2d\u3067ZIP\u5f62\u5f0f\u306e\u30d5\u30a1\u30a4\u30eb\u3092\u6271\u3046\u3053\u3068\u306f\u3042\u308a\u307e\u3057\u305f\u304c\u3001\u5727\u7e2e\u30fb\u89e3\u51cd\u51e6\u7406\u3060\u3051\u3092\u8a18\u4e8b\u306b\u3059\u308b\u3053\u3068\u306f\u7121\u304b\u3063\u305f\u306e\u3067\u3001\u7c21\u5358\u306b\u30b3\u30fc\u30c9\u3092\u307e\u3068\u3081\u3066\u307f\u307e\u3057\u305f\u3002<\/p>\n<pre class=\"brush: vb; title: ; notranslate\" title=\"\">Option Explicit\r\n\r\nPublic Sub ZipSample()\r\n  ZipFileOrFolder &quot;C:\\Test\\Files&quot; '\u30d5\u30a9\u30eb\u30c0\u5727\u7e2e\r\n  MsgBox &quot;\u51e6\u7406\u304c\u7d42\u4e86\u3057\u307e\u3057\u305f\u3002&quot;, vbInformation + vbSystemModal\r\nEnd Sub\r\n\r\nPublic Sub UnZipSample()\r\n  UnZipFile &quot;C:\\Test\\Files\\Test.zip&quot;\r\n  MsgBox &quot;\u51e6\u7406\u304c\u7d42\u4e86\u3057\u307e\u3057\u305f\u3002&quot;, vbInformation + vbSystemModal\r\nEnd Sub\r\n\r\nPublic Sub ZipFileOrFolder(ByVal SrcPath As Variant, _\r\n                           Optional ByVal DestFolderPath As Variant = &quot;&quot;)\r\n'\u30d5\u30a1\u30a4\u30eb\u30fb\u30d5\u30a9\u30eb\u30c0\u3092ZIP\u5f62\u5f0f\u3067\u5727\u7e2e\r\n'SrcPath\uff1a\u5143\u30d5\u30a1\u30a4\u30eb\u30fb\u30d5\u30a9\u30eb\u30c0\r\n'DestFolderPath\uff1a\u51fa\u529b\u5148\u3001\u6307\u5b9a\u3057\u306a\u3044\u5834\u5408\u306f\u5143\u30d5\u30a1\u30a4\u30eb\u30fb\u30d5\u30a9\u30eb\u30c0\u3068\u540c\u3058\u5834\u6240\r\n  Dim DestFilePath As Variant\r\n  \r\n  With CreateObject(&quot;Scripting.FileSystemObject&quot;)\r\n    If IsFolder(DestFolderPath) = False Then\r\n      If IsFolder(SrcPath) = True Then\r\n        DestFolderPath = SrcPath\r\n      ElseIf IsFile(SrcPath) = True Then\r\n        DestFolderPath = .GetFile(SrcPath).ParentFolder.Path\r\n      Else: Exit Sub\r\n      End If\r\n    End If\r\n    DestFilePath = AddPathSeparator(DestFolderPath) &amp; _\r\n                     .GetBaseName(SrcPath) &amp; &quot;.zip&quot;\r\n    '\u7a7a\u306eZIP\u30d5\u30a1\u30a4\u30eb\u4f5c\u6210\r\n    With .CreateTextFile(DestFilePath, True)\r\n      .Write ChrW(&amp;H50) &amp; ChrW(&amp;H4B) &amp; ChrW(&amp;H5) &amp; ChrW(&amp;H6) &amp; String(18, ChrW(0))\r\n      .Close\r\n    End With\r\n  End With\r\n  \r\n  With CreateObject(&quot;Shell.Application&quot;)\r\n    With .NameSpace(DestFilePath)\r\n      .CopyHere SrcPath\r\n      While .Items.Count &lt; 1\r\n        DoEvents\r\n      Wend\r\n    End With\r\n  End With\r\nEnd Sub\r\n\r\nPublic Sub UnZipFile(ByVal SrcPath As Variant, _\r\n                     Optional ByVal DestFolderPath As Variant = &quot;&quot;)\r\n'ZIP\u30d5\u30a1\u30a4\u30eb\u3092\u89e3\u51cd\r\n'SrcPath\uff1a\u5143\u30d5\u30a1\u30a4\u30eb\r\n'DestFolderPath\uff1a\u51fa\u529b\u5148\u3001\u6307\u5b9a\u3057\u306a\u3044\u5834\u5408\u306f\u5143\u30d5\u30a1\u30a4\u30eb\u3068\u540c\u3058\u5834\u6240\r\n'\u203b\u51fa\u529b\u5148\u306b\u540c\u540d\u30d5\u30a1\u30a4\u30eb\u304c\u3042\u3063\u305f\u5834\u5408\u306f\u30e6\u30fc\u30b6\u30fc\u5224\u65ad\u3067\u51e6\u7406\r\n  With CreateObject(&quot;Scripting.FileSystemObject&quot;)\r\n    If .FileExists(SrcPath) = False Then Exit Sub\r\n    If LCase(.GetExtensionName(SrcPath)) &lt;&gt; &quot;zip&quot; Then Exit Sub\r\n    If IsFolder(DestFolderPath) = False Then\r\n      DestFolderPath = .GetFile(SrcPath).ParentFolder.Path\r\n    End If\r\n  End With\r\n  \r\n  With CreateObject(&quot;Shell.Application&quot;)\r\n    .NameSpace(DestFolderPath).CopyHere .NameSpace(SrcPath).Items\r\n  End With\r\nEnd Sub\r\n\r\nPrivate Function IsFolder(ByVal SrcPath As String) As Boolean\r\n  IsFolder = CreateObject(&quot;Scripting.FileSystemObject&quot;).FolderExists(SrcPath)\r\nEnd Function\r\n\r\nPrivate Function IsFile(ByVal SrcPath As String) As Boolean\r\n  IsFile = CreateObject(&quot;Scripting.FileSystemObject&quot;).FileExists(SrcPath)\r\nEnd Function\r\n\r\nPrivate Function AddPathSeparator(ByVal SrcPath As String) As String\r\n  If Right(SrcPath, 1) &lt;&gt; ChrW(92) Then SrcPath = SrcPath &amp; ChrW(92)\r\n  AddPathSeparator = SrcPath\r\nEnd Function<\/pre>\n<p>Shell\u3067\u51e6\u7406\u3059\u308b\u305f\u3081\u3001\u5916\u90e8\u306e\u30a2\u30d7\u30ea\u30b1\u30fc\u30b7\u30e7\u30f3\u3084DLL\u304c\u4e0d\u8981\u306a\u70b9\u306f\u30e1\u30ea\u30c3\u30c8\u3068\u3057\u3066\u6319\u3052\u3089\u308c\u308b\u306e\u3067\u3059\u304c\u3001\u4e0a\u8a18\u30b3\u30fc\u30c9\u306e\u51e6\u7406\u306f<a href=\"https:\/\/support.microsoft.com\/ja-jp\/kb\/2679832\" title=\"CopyHere \u30e1\u30bd\u30c3\u30c9\u304b\u3089 Zip \u30d5\u30a1\u30a4\u30eb\u3092\u51e6\u7406\u3059\u308b\u3053\u3068\u306f\u3067\u304d\u307e\u305b\u3093\" target=\"_blank\">\u201c\u30b5\u30dd\u30fc\u30c8\u5bfe\u8c61\u5916\u201d<\/a>\u3068\u306a\u3063\u3066\u3044\u308b\u306e\u3067\u3001\u5834\u5408\u306b\u3088\u3063\u3066\u306f\u4e0a\u624b\u304f\u51e6\u7406\u3067\u304d\u306a\u3044\u304b\u3082\u3057\u308c\u307e\u305b\u3093\u3002<\/p>\n<div id=\"single_banner_area2\" class=\"clearfix one_banner\">\n<div class=\"single_banner single_banner_left\">\n<script async src=\"https:\/\/pagead2.googlesyndication.com\/pagead\/js\/adsbygoogle.js\"><\/script>\r\n<!-- \u8a18\u4e8b\u4e2d(\u30c7\u30a3\u30b9\u30d7\u30ec\u30a4\u5e83\u544a\u30e6\u30cb\u30c3\u30c8) -->\r\n<ins class=\"adsbygoogle\"\r\n     style=\"display:block\"\r\n     data-ad-client=\"ca-pub-7306936664602087\"\r\n     data-ad-slot=\"5429724765\"\r\n     data-ad-format=\"auto\"\r\n     data-full-width-responsive=\"true\"><\/ins>\r\n<script>\r\n     (adsbygoogle = window.adsbygoogle || []).push({});\r\n<\/script>\n<\/div>\n<div class=\"single_banner single_banner_right\">\n<a href=\"\" target=\"_blank\"><img decoding=\"async\" src=\"\" alt=\"\" title=\"\" \/><\/a>\n<\/div>\n<\/div>\n\n<h4 class=\"style4a\">\u95a2\u9023\u8a18\u4e8b<\/h4>\n<div class=\"cardlink\"><a href=\"https:\/\/www.ka-net.org\/blog\/?p=7953\"><div class=\"cardlink_thumbnail\"><img src='https:\/\/www.ka-net.org\/blog\/wp-content\/uploads\/eyecatch-OfficeVBA-120x120.png' alt='7-Zip\u3067\u5727\u7e2e\u30fb\u89e3\u51cd\u3092\u884c\u3046VBA\u30de\u30af\u30ed' width=120 height=120 \/><\/a><\/div><div class=\"cardlink_content\"><span class=\"timestamp\">2017.02.09<\/span><div class=\"cardlink_title\"><a href=\"https:\/\/www.ka-net.org\/blog\/?p=7953\">7-Zip\u3067\u5727\u7e2e\u30fb\u89e3\u51cd\u3092\u884c\u3046VBA\u30de\u30af\u30ed <\/a><\/div><div class=\"cardlink_excerpt\">\u300c7-Zip VBA\u300d\u3068\u3044\u3063\u305f\u30ad\u30fc\u30ef\u30fc\u30c9\u691c\u7d22\u3067\u306e\u30a2\u30af\u30bb\u30b9\u304c\u3042\u308a\u307e\u3057\u305f\u3002\r\n\r\n\u6050\u3089\u304f\u300c\u5727\u7e2e\u30fb\u89e3\u51cd\u30bd\u30d5\u30c8 7-Zip\u300d\u3092\u4f7f\u3063\u3066\u3001\u30d5\u30a1\u30a4\u30eb\u306e\u5727\u7e2e\u3084\u89e3\u51cd\u3092\u884c\u3046\u30de\u30af\u30ed\u3092\u63a2\u3057\u3066\u3044\u308b\u65b9\u3060\u308d\u3046\u3068\u601d\u3044\u307e\u3059\u3002\r\n\r\n\u4ee5\u524d\u4e0b\u8a18\u8a18\u4e8b\u3067Shell\u3092\u4f7f\u3063\u305fZIP\u5727\u7e2e\u30fb\u89e3\u51cd\u3092\u884c\u3046\u30de\u30af\u30ed\u3092...<\/div><\/div><div class=\"cardlink_footer\"><\/div><\/div>\n","protected":false},"excerpt":{"rendered":"\u3053\u306e\u8a18\u4e8b\u306e\u3088\u3046\u306b\u3001\u51e6\u7406\u306e\u4e2d\u3067ZIP\u5f62\u5f0f\u306e\u30d5\u30a1\u30a4\u30eb\u3092\u6271\u3046\u3053\u3068\u306f\u3042\u308a\u307e\u3057\u305f\u304c\u3001\u5727\u7e2e\u30fb\u89e3\u51cd\u51e6\u7406\u3060\u3051\u3092\u8a18\u4e8b\u306b\u3059\u308b\u3053\u3068\u306f\u7121\u304b\u3063\u305f\u306e\u3067\u3001\u7c21\u5358\u306b\u30b3\u30fc\u30c9\u3092\u307e\u3068\u3081\u3066\u307f\u307e\u3057\u305f\u3002 Option Explicit Public Sub ZipS [&hellip;]","protected":false},"author":1,"featured_media":7120,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_jetpack_memberships_contains_paid_content":false,"footnotes":"","jetpack_publicize_message":"MS\u306e\u30b5\u30dd\u30fc\u30c8\u5916\u3067\u3042\u308b\u70b9\u306f\u6ce8\u610f\u304c\u5fc5\u8981\u3067\u3059\u3002 [ZIP\u5f62\u5f0f\u3067\u5727\u7e2e\u30fb\u89e3\u51cd\u3092\u884c\u3046VBA\u30de\u30af\u30ed]","jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":true,"jetpack_social_options":{"image_generator_settings":{"template":"highway","default_image_id":0,"font":"","enabled":false},"version":2}},"categories":[4,48,49,58],"tags":[],"class_list":["post-7605","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-office","category-excel-office","category-word-office","category-powerpoint"],"aioseo_notices":[],"jetpack_publicize_connections":[],"jetpack_featured_media_url":"https:\/\/www.ka-net.org\/blog\/wp-content\/uploads\/eyecatch-OfficeVBA.png","jetpack_shortlink":"https:\/\/wp.me\/p4UZZr-1YF","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/www.ka-net.org\/blog\/index.php?rest_route=\/wp\/v2\/posts\/7605","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=7605"}],"version-history":[{"count":3,"href":"https:\/\/www.ka-net.org\/blog\/index.php?rest_route=\/wp\/v2\/posts\/7605\/revisions"}],"predecessor-version":[{"id":8090,"href":"https:\/\/www.ka-net.org\/blog\/index.php?rest_route=\/wp\/v2\/posts\/7605\/revisions\/8090"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.ka-net.org\/blog\/index.php?rest_route=\/wp\/v2\/media\/7120"}],"wp:attachment":[{"href":"https:\/\/www.ka-net.org\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=7605"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.ka-net.org\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=7605"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.ka-net.org\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=7605"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}