{"id":6455,"date":"2015-12-16T10:27:07","date_gmt":"2015-12-16T01:27:07","guid":{"rendered":"http:\/\/www.ka-net.org\/blog\/?p=6455"},"modified":"2015-12-16T10:27:07","modified_gmt":"2015-12-16T01:27:07","slug":"msg%e3%83%95%e3%82%a1%e3%82%a4%e3%83%ab%e3%81%8b%e3%82%89%e6%b7%bb%e4%bb%98%e3%83%95%e3%82%a1%e3%82%a4%e3%83%ab%e3%82%92%e6%8a%bd%e5%87%ba%e3%81%99%e3%82%8bvbscript","status":"publish","type":"post","link":"https:\/\/www.ka-net.org\/blog\/?p=6455","title":{"rendered":"msg\u30d5\u30a1\u30a4\u30eb\u304b\u3089\u6dfb\u4ed8\u30d5\u30a1\u30a4\u30eb\u3092\u62bd\u51fa\u3059\u308bVBScript"},"content":{"rendered":"<p>\u300c<span style=\"color: #ff0000; font-weight: bold;\">msg\u30d5\u30a1\u30a4\u30eb\u304b\u3089\u6dfb\u4ed8\u30d5\u30a1\u30a4\u30eb\u3092\u62bd\u51fa\u3059\u308b\u30b9\u30af\u30ea\u30d7\u30c8<\/span>\u300d\u3068\u3044\u3063\u305f\u30ad\u30fc\u30ef\u30fc\u30c9\u3067\u306e\u30a2\u30af\u30bb\u30b9\u304c\u3042\u308a\u307e\u3057\u305f\u3002<\/p>\n<p>\u6050\u3089\u304f\u30a8\u30af\u30b9\u30dd\u30fc\u30c8\u3057\u305fOutlook\u306e\u30e1\u30fc\u30eb\u30d5\u30a1\u30a4\u30eb(msg)\u304b\u3089\u6dfb\u4ed8\u30d5\u30a1\u30a4\u30eb\u3060\u3051\u3092\u53d6\u308a\u51fa\u3059\u306e\u304c\u76ee\u7684\u306a\u306e\u3060\u308d\u3046\u3068\u601d\u3044\u307e\u3059\u3002<\/p>\n<p>\u76ee\u7684\u306e\u51e6\u7406\u306f\u3001Outlook\u7d4c\u7531\u3067\u3042\u308c\u3070\u3001NameSpace\u30aa\u30d6\u30b8\u30a7\u30af\u30c8\u306e<a href=\"https:\/\/msdn.microsoft.com\/ja-jp\/library\/ff869601.aspx\" title=\"OpenSharedItem \u3092\u4f7f\u7528\u3057\u3066\u3001\u4fdd\u5b58\u3057\u305f\u30a2\u30a4\u30c6\u30e0\u3092\u30a4\u30f3\u30dd\u30fc\u30c8\u3057\u307e\u3059\u3002\" target=\"_blank\">OpenSharedItem<\/a>\u30e1\u30bd\u30c3\u30c9\u3068Attachment\u30aa\u30d6\u30b8\u30a7\u30af\u30c8\u306e<a href=\"https:\/\/msdn.microsoft.com\/ja-jp\/library\/ff869359.aspx\" title=\"Attachment.SaveAsFile \u30e1\u30bd\u30c3\u30c9 (Outlook)(\u6a5f\u68b0\u7ffb\u8a33)\" target=\"_blank\">SaveAsFile<\/a>\u30e1\u30bd\u30c3\u30c9\u3092\u4f7f\u3046\u3053\u3068\u3067\u51e6\u7406\u3067\u304d\u308b\u304b\u3068\u601d\u3044\u307e\u3059\u3002<\/p>\n<pre class=\"brush: vb; title: ; notranslate\" title=\"\">'*************************************************************\r\n' \u30c9\u30e9\u30c3\u30b0\uff06\u30c9\u30ed\u30c3\u30d7\u3057\u305fmsg\u30d5\u30a1\u30a4\u30eb\u304b\u3089\u6dfb\u4ed8\u30d5\u30a1\u30a4\u30eb\u3092\u62bd\u51fa\u3057\u3001\r\n' \u6307\u5b9a\u3057\u305f\u30d5\u30a9\u30eb\u30c0\u306b\u4fdd\u5b58\u3059\u308b\u30b9\u30af\u30ea\u30d7\u30c8\r\n' \r\n' 2015\/12\/16 @kinuasa\r\n'*************************************************************\r\n\r\nOption Explicit\r\n\r\nDim args\r\nDim olApp\r\nDim i\r\nConst SaveFolderPath = &quot;C:\\Test&quot; '\u6dfb\u4ed8\u30d5\u30a1\u30a4\u30eb\u306e\u4fdd\u5b58\u5148\u30d5\u30a9\u30eb\u30c0(\u203b\u8981\u5909\u66f4)\r\n\r\nSet args = WScript.Arguments\r\nIf args.Count &lt; 1 Then\r\n  MsgBox &quot;msg\u30d5\u30a1\u30a4\u30eb\u3092\u5f53\u30b9\u30af\u30ea\u30d7\u30c8\u30d5\u30a1\u30a4\u30eb\u306b\u30c9\u30e9\u30c3\u30b0\uff06\u30c9\u30ed\u30c3\u30d7\u3057\u3066\u304f\u3060\u3055\u3044\u3002&quot;, vbExclamation + vbSystemModal\r\n  WScript.Quit\r\nEnd If\r\n\r\nWith CreateObject(&quot;Scripting.FileSystemObject&quot;)\r\n  If .FolderExists(SaveFolderPath) = False Then\r\n    MsgBox &quot;\u6dfb\u4ed8\u30d5\u30a1\u30a4\u30eb\u306e\u4fdd\u5b58\u5148\u30d5\u30a9\u30eb\u30c0\u304c\u898b\u3064\u304b\u308a\u307e\u305b\u3093\u3067\u3057\u305f\u3002&quot; &amp; vbCrLf &amp; _\r\n           &quot;\u51e6\u7406\u3092\u4e2d\u6b62\u3057\u307e\u3059\u3002&quot;, vbCritical + vbSystemModal\r\n    WScript.Quit\r\n  End If\r\n  Set olApp = CreateObject(&quot;Outlook.Application&quot;)\r\n  For i = 0 To args.Count - 1\r\n    If .FileExists(args(i)) = True Then\r\n      Select Case LCase(.GetExtensionName(args(i)))\r\n        Case &quot;msg&quot; 'msg\u30d5\u30a1\u30a4\u30eb\u306e\u307f\u51e6\u7406\r\n          SaveMsgAttachments olApp, args(i), AddPathSeparator(SaveFolderPath)\r\n      End Select\r\n    End If\r\n  Next\r\n  olApp.Quit\r\nEnd With\r\n\r\nMsgBox &quot;\u51e6\u7406\u304c\u7d42\u4e86\u3057\u307e\u3057\u305f\u3002&quot;, vbInformation + vbSystemModal\r\n\r\nPrivate Sub SaveMsgAttachments(ByVal OutlookApp, ByVal MsgFilePath, ByVal SaveFolderPath)\r\n  Dim itm 'Outlook.MailItem\r\n  Dim atc 'Outlook.Attachment\r\n  Dim fn\r\n  \r\n  With OutlookApp.GetNamespace(&quot;MAPI&quot;)\r\n    Set itm = .OpenSharedItem(MsgFilePath)\r\n    Select Case LCase(TypeName(itm))\r\n      Case &quot;mailitem&quot;\r\n        If itm.Attachments.Count &lt; 1 Then\r\n          MsgBox &quot;\u6dfb\u4ed8\u30d5\u30a1\u30a4\u30eb\u304c\u3042\u308a\u307e\u305b\u3093\u3002&quot; &amp; vbCrLf &amp; _\r\n                 &quot;(\u30d5\u30a1\u30a4\u30eb\u540d\uff1a&quot; &amp; MsgFilePath &amp; &quot;)&quot;, vbExclamation + vbSystemModal\r\n          Exit Sub\r\n        Else\r\n          With CreateObject(&quot;Scripting.FileSystemObject&quot;)\r\n            For Each atc In itm.Attachments\r\n              fn = SaveFolderPath &amp; atc.FileName\r\n              If .FileExists(fn) = True Then\r\n                .DeleteFile fn, True '\u540c\u540d\u306e\u30d5\u30a1\u30a4\u30eb\u304c\u3042\u3063\u305f\u3089\u4e8b\u524d\u306b\u524a\u9664\r\n              End If\r\n              atc.SaveAsFile fn\r\n            Next\r\n          End With\r\n        End If\r\n    End Select\r\n  End With\r\nEnd Sub\r\n\r\nPrivate Function AddPathSeparator(ByVal s)\r\n  If Right(s, 1) &lt;&gt; ChrW(92) Then s = s &amp; ChrW(92)\r\n  AddPathSeparator = s\r\nEnd Function<\/pre>\n<p>\u4e0a\u8a18\u30b3\u30fc\u30c9\u3067\u306f\u3001msg\u30d5\u30a1\u30a4\u30eb\u3092\u30b9\u30af\u30ea\u30d7\u30c8\u30d5\u30a1\u30a4\u30eb\u306b\u30c9\u30e9\u30c3\u30b0\uff06\u30c9\u30ed\u30c3\u30d7\u3059\u308b\u3053\u3068\u3067\u3001\u6307\u5b9a\u3057\u305f\u30d5\u30a9\u30eb\u30c0\u306b\u6dfb\u4ed8\u30d5\u30a1\u30a4\u30eb\u3092\u4fdd\u5b58\u3059\u308b\u3053\u3068\u304c\u51fa\u6765\u307e\u3059\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"\u300cmsg\u30d5\u30a1\u30a4\u30eb\u304b\u3089\u6dfb\u4ed8\u30d5\u30a1\u30a4\u30eb\u3092\u62bd\u51fa\u3059\u308b\u30b9\u30af\u30ea\u30d7\u30c8\u300d\u3068\u3044\u3063\u305f\u30ad\u30fc\u30ef\u30fc\u30c9\u3067\u306e\u30a2\u30af\u30bb\u30b9\u304c\u3042\u308a\u307e\u3057\u305f\u3002 \u6050\u3089\u304f\u30a8\u30af\u30b9\u30dd\u30fc\u30c8\u3057\u305fOutlook\u306e\u30e1\u30fc\u30eb\u30d5\u30a1\u30a4\u30eb(msg)\u304b\u3089\u6dfb\u4ed8\u30d5\u30a1\u30a4\u30eb\u3060\u3051\u3092\u53d6\u308a\u51fa\u3059\u306e\u304c\u76ee\u7684\u306a\u306e\u3060\u308d\u3046\u3068\u601d\u3044\u307e\u3059 [&hellip;]","protected":false},"author":1,"featured_media":7124,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_jetpack_memberships_contains_paid_content":false,"footnotes":"","jetpack_publicize_message":"[msg\u30d5\u30a1\u30a4\u30eb\u304b\u3089\u6dfb\u4ed8\u30d5\u30a1\u30a4\u30eb\u3092\u62bd\u51fa\u3059\u308bVBScript]","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":[6,68],"tags":[],"class_list":["post-6455","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-vbs","category-outlook"],"aioseo_notices":[],"jetpack_publicize_connections":[],"jetpack_featured_media_url":"https:\/\/www.ka-net.org\/blog\/wp-content\/uploads\/eyecatch-Outlook.png","jetpack_shortlink":"https:\/\/wp.me\/p4UZZr-1G7","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/www.ka-net.org\/blog\/index.php?rest_route=\/wp\/v2\/posts\/6455","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=6455"}],"version-history":[{"count":2,"href":"https:\/\/www.ka-net.org\/blog\/index.php?rest_route=\/wp\/v2\/posts\/6455\/revisions"}],"predecessor-version":[{"id":6457,"href":"https:\/\/www.ka-net.org\/blog\/index.php?rest_route=\/wp\/v2\/posts\/6455\/revisions\/6457"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.ka-net.org\/blog\/index.php?rest_route=\/wp\/v2\/media\/7124"}],"wp:attachment":[{"href":"https:\/\/www.ka-net.org\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=6455"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.ka-net.org\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=6455"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.ka-net.org\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=6455"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}