{"id":12219,"date":"2019-10-01T15:00:34","date_gmt":"2019-10-01T06:00:34","guid":{"rendered":"https:\/\/www.ka-net.org\/blog\/?p=12219"},"modified":"2019-10-01T15:29:15","modified_gmt":"2019-10-01T06:29:15","slug":"powershellword%e6%96%87%e6%9b%b8%e3%81%ae%e9%80%8f%e3%81%8b%e3%81%97%e6%96%87%e5%ad%97%e3%82%92%e5%a4%89%e6%9b%b4%e3%81%99%e3%82%8b%e3%82%b9%e3%82%af%e3%83%aa%e3%83%97%e3%83%88","status":"publish","type":"post","link":"https:\/\/www.ka-net.org\/blog\/?p=12219","title":{"rendered":"[PowerShell]Word\u6587\u66f8\u306e\u900f\u304b\u3057\u6587\u5b57\u3092\u5909\u66f4\u3059\u308b\u30b9\u30af\u30ea\u30d7\u30c8"},"content":{"rendered":"<p><a href=\"https:\/\/social.msdn.microsoft.com\/Forums\/office\/en-us\/home?forum=worddev\" title=\"Msdn forums - Word for Developers\" target=\"_blank\" rel=\"noopener noreferrer\">MSDN\u30d5\u30a9\u30fc\u30e9\u30e0<\/a>\u306b<i>\u300cPowerShell\u3092\u4f7f\u3063\u3066\u3001Word\u6587\u66f8\u306e\u900f\u304b\u3057\u6587\u5b57\u3092\u5909\u66f4\u3057\u305f\u3044\u300d<\/i>\u3001\u3068\u306e\u8cea\u554f\u304c\u3042\u308a\u307e\u3057\u305f\u3002<\/p>\n<div class=\"linkcard\"><div class=\"lkc-external-wrap\"><a class=\"lkc-link no_icon\" href=\"https:\/\/social.msdn.microsoft.com\/Forums\/en-us\/worddev\/thread\/1533914f-2982-49e6-a865-485c3eaffb98\" target=\"_blank\" rel=\"external nofollow noopener\"><div class=\"lkc-card\"><div class=\"lkc-info\"><div class=\"lkc-favicon\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/www.google.com\/s2\/favicons?domain=social.msdn.microsoft.com\" alt=\"\" width=\"16\" height=\"16\" \/><\/div><div class=\"lkc-domain\">social.msdn.microsoft.com<\/div><\/div><div class=\"lkc-content\"><figure class=\"lkc-thumbnail\"><img decoding=\"async\" class=\"lkc-thumbnail-img\" src=\"https:\/\/s.wordpress.com\/mshots\/v1\/https%3A%2F%2Fsocial.msdn.microsoft.com%2FForums%2Fen-us%2Fworddev%2Fthread%2F1533914f-2982-49e6-a865-485c3eaffb98?w=100\" width=\"100px\" height=\"108px\" alt=\"\" \/><\/figure><div class=\"lkc-title\">Powershell command to replace or remove Watermark in Microsoft Word<\/div><div class=\"lkc-url\" title=\"https:\/\/social.msdn.microsoft.com\/Forums\/en-us\/worddev\/thread\/1533914f-2982-49e6-a865-485c3eaffb98\">https:\/\/social.msdn.microsoft.com\/Forums\/en-us\/worddev\/thread\/1533914f-2982-49e6-a865-485c3eaffb98<\/div><\/div><div class=\"clear\"><\/div><\/div><\/a><\/div><\/div>\n<p>\u3059\u3050\u306b\u601d\u3044\u3064\u304f\u306e\u306f\u3001PowerShell\u304b\u3089Word\u30a2\u30d7\u30ea\u30b1\u30fc\u30b7\u30e7\u30f3\u3092\u64cd\u4f5c\u3059\u308b\u3053\u3068\u3067\u3059\u304c\u3001\u4e0b\u8a18\u30b3\u30fc\u30c9\u306e\u3088\u3046\u306bCOM\u30aa\u30d6\u30b8\u30a7\u30af\u30c8\u306e\u89e3\u653e\u51e6\u7406\u304c\u5fc5\u8981\u306b\u306a\u308b\u306e\u3067\u3001\u975e\u5e38\u306b\u5197\u9577\u3067\u3059\u3002<\/p>\n<pre class=\"brush: powershell; title: ; notranslate\" title=\"\">function ModifyWaterMarkText($file_path, $new_text){\r\n  $objApp = New-Object -ComObject Word.Application\r\n  $objApp.Visible = $true\r\n  $objDocs = $objApp.Documents #Word.Documents\r\n  $objDoc = $objDocs.Open($file_path) #Word.Document\r\n  $objWin = $objDoc.ActiveWindow #Word.Window\r\n  $objPane = $objWin.ActivePane #Word.Pane\r\n  $objView = $objPane.View #Word.View\r\n  $tmpSv = $objView.SeekView\r\n  $objView.SeekView = 9 #WdSeekView.wdSeekCurrentPageHeader\r\n  $objSel = $objApp.Selection #Word.Selection\r\n  $objHF = $objSel.HeaderFooter #Word.HeaderFooter\r\n  $objShapes = $objHF.Shapes #Word.Shapes\r\n  If($objShapes.Count -gt 0){\r\n    $objShape = $objShapes.Item(1) #Word.Shape\r\n    $objTef = $objShape.TextEffect #Word.TextEffectFormat\r\n    $objTef.Text = $new_text\r\n  }\r\n  $objView.SeekView = $tmpSv\r\n  $objDoc.Close(-1) #WdSaveOptions.wdSaveChanges\r\n\r\n  &#x5B;Runtime.Interopservices.Marshal]::ReleaseComObject($objTef) &gt; $null\r\n  &#x5B;Runtime.Interopservices.Marshal]::ReleaseComObject($objShape) &gt; $null\r\n  &#x5B;Runtime.Interopservices.Marshal]::ReleaseComObject($objShapes) &gt; $null\r\n  &#x5B;Runtime.Interopservices.Marshal]::ReleaseComObject($objHF) &gt; $null\r\n  &#x5B;Runtime.Interopservices.Marshal]::ReleaseComObject($objSel) &gt; $null\r\n  &#x5B;Runtime.Interopservices.Marshal]::ReleaseComObject($objView) &gt; $null\r\n  &#x5B;Runtime.Interopservices.Marshal]::ReleaseComObject($objPane) &gt; $null\r\n  &#x5B;Runtime.Interopservices.Marshal]::ReleaseComObject($objWin) &gt; $null\r\n  &#x5B;Runtime.Interopservices.Marshal]::ReleaseComObject($objDoc) &gt; $null\r\n  &#x5B;Runtime.Interopservices.Marshal]::ReleaseComObject($objDocs) &gt; $null\r\n\r\n  &#x5B;GC]::Collect()\r\n  &#x5B;GC]::WaitForPendingFinalizers()\r\n  &#x5B;GC]::Collect()\r\n\r\n  $objApp.Quit()\r\n  &#x5B;Runtime.Interopservices.Marshal]::ReleaseComObject($objApp) &gt; $null\r\n\r\n  &#x5B;GC]::Collect()\r\n  &#x5B;GC]::WaitForPendingFinalizers()\r\n  &#x5B;GC]::Collect()\r\n}\r\n\r\nModifyWaterMarkText &quot;C:\\wk\\SampleWaterMark.docx&quot; &quot;Internal&quot;<\/pre>\n<p>\u3059\u3079\u3066\u306e\u30bb\u30af\u30b7\u30e7\u30f3\u3092\u30eb\u30fc\u30d7\u3055\u305b\u308c\u3070\u591a\u5c11\u306f\u30b3\u30fc\u30c9\u304c\u77ed\u304f\u306a\u308b\u304b\u3068\u601d\u3044\u307e\u3057\u305f\u304c\u2193\u3001\u3084\u306f\u308a\u3053\u3061\u3089\u3082\u5197\u9577\u3067\u3059\u3002<\/p>\n<pre class=\"brush: powershell; title: ; notranslate\" title=\"\">function ModifyWaterMarkText($file_path, $new_text){\r\n  $objApp = New-Object -ComObject Word.Application\r\n  $objApp.Visible = $true\r\n  $objDocs = $objApp.Documents #Word.Documents\r\n  $objDoc = $objDocs.Open($file_path) #Word.Document\r\n  $objSecs = $objDoc.Sections #Word.Sections\r\n  for($i=1; $i -le $objSecs.Count; $i++){\r\n    $objSec = $objSecs.Item($i)\r\n    $objHdrs = $objSec.Headers #Word.HeadersFooters\r\n    for($j=1; $j -le $objHdrs.Count; $j++){\r\n      $objHdr = $objHdrs.Item($j) #Word.HeaderFooter\r\n      $objShapes = $objHdr.Shapes\r\n      If($objShapes.Count -gt 0){\r\n        $objShape = $objShapes.Item(1) #Word.Shape\r\n        $objTef = $objShape.TextEffect #Word.TextEffectFormat\r\n        $objTef.Text = $new_text\r\n        &#x5B;Runtime.Interopservices.Marshal]::ReleaseComObject($objTef) &gt; $null\r\n        &#x5B;Runtime.Interopservices.Marshal]::ReleaseComObject($objShape) &gt; $null\r\n      }\r\n      &#x5B;Runtime.Interopservices.Marshal]::ReleaseComObject($objShapes) &gt; $null\r\n      &#x5B;Runtime.Interopservices.Marshal]::ReleaseComObject($objHdr) &gt; $null\r\n    }\r\n    &#x5B;Runtime.Interopservices.Marshal]::ReleaseComObject($objHdrs) &gt; $null\r\n    &#x5B;Runtime.Interopservices.Marshal]::ReleaseComObject($objSec) &gt; $null\r\n  }\r\n  &#x5B;Runtime.Interopservices.Marshal]::ReleaseComObject($objSecs) &gt; $null\r\n  $objDoc.Close(-1) #WdSaveOptions.wdSaveChanges\r\n  &#x5B;Runtime.Interopservices.Marshal]::ReleaseComObject($objDoc) &gt; $null\r\n  &#x5B;Runtime.Interopservices.Marshal]::ReleaseComObject($objDocs) &gt; $null\r\n\r\n  &#x5B;GC]::Collect()\r\n  &#x5B;GC]::WaitForPendingFinalizers()\r\n  &#x5B;GC]::Collect()\r\n\r\n  $objApp.Quit()\r\n  &#x5B;Runtime.Interopservices.Marshal]::ReleaseComObject($objApp) &gt; $null\r\n\r\n  &#x5B;GC]::Collect()\r\n  &#x5B;GC]::WaitForPendingFinalizers()\r\n  &#x5B;GC]::Collect()\r\n}\r\n\r\nModifyWaterMarkText &quot;C:\\wk\\SampleWaterMark.docx&quot; &quot;Internal&quot;<\/pre>\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<p>Word\u3084Excel\u3068\u3044\u3063\u305fOffice\u30a2\u30d7\u30ea\u30b1\u30fc\u30b7\u30e7\u30f3\u3092\u5916\u90e8\u306e\u30d7\u30ed\u30b0\u30e9\u30e0\u304b\u3089\u64cd\u4f5c\u3059\u308b\u5834\u5408\u3001\u7279\u306bPowerShell\u3092\u4f7f\u308f\u306a\u3051\u308c\u3070\u306a\u3089\u306a\u3044\u7406\u7531\u304c\u7121\u3044\u306e\u3067\u3042\u308c\u3070\u3001VBS\u3084VBA\u3067\u51e6\u7406\u3057\u305f\u65b9\u304c\u3001\u500b\u4eba\u7684\u306b\u306f\u697d\u3060\u3068\u601d\u3044\u307e\u3059\u3002<\/p>\n<h4 class=\"style4a\">\u53c2\u8003Web\u30da\u30fc\u30b8<\/h4>\n<div class=\"linkcard\"><div class=\"lkc-external-wrap\"><a class=\"lkc-link no_icon\" href=\"https:\/\/social.msdn.microsoft.com\/Forums\/ja-jp\/officesupportteamja\/thread\/5deec897-a897-404b-a610-f7d894fde1b3\" target=\"_blank\" rel=\"external nofollow noopener\"><div class=\"lkc-card\"><div class=\"lkc-info\"><div class=\"lkc-favicon\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/www.google.com\/s2\/favicons?domain=social.msdn.microsoft.com\" alt=\"\" width=\"16\" height=\"16\" \/><\/div><div class=\"lkc-domain\">social.msdn.microsoft.com<\/div><\/div><div class=\"lkc-content\"><figure class=\"lkc-thumbnail\"><img decoding=\"async\" class=\"lkc-thumbnail-img\" src=\"https:\/\/s.wordpress.com\/mshots\/v1\/https%3A%2F%2Fsocial.msdn.microsoft.com%2FForums%2Fja-jp%2Fofficesupportteamja%2Fthread%2F5deec897-a897-404b-a610-f7d894fde1b3?w=100\" width=\"100px\" height=\"108px\" alt=\"\" \/><\/figure><div class=\"lkc-title\">Office &#12458;&#12540;&#12488;&#12513;&#12540;&#12471;&#12519;&#12531;&amp;#1239...<\/div><div class=\"lkc-url\" title=\"https:\/\/social.msdn.microsoft.com\/Forums\/ja-jp\/officesupportteamja\/thread\/5deec897-a897-404b-a610-f7d894fde1b3\">https:\/\/social.msdn.microsoft.com\/Forums\/ja-jp\/officesupportteamja\/thread\/5deec897-a897-404b-a610-f7d894fde1b3<\/div><\/div><div class=\"clear\"><\/div><\/div><\/a><\/div><\/div>\n<div class=\"linkcard\"><div class=\"lkc-external-wrap\"><a class=\"lkc-link no_icon\" href=\"https:\/\/social.msdn.microsoft.com\/Forums\/ja-jp\/officesupportteamja\/thread\/0d9c6273-bade-4f6a-a0de-5adb748d15eb\" target=\"_blank\" rel=\"external nofollow noopener\"><div class=\"lkc-card\"><div class=\"lkc-info\"><div class=\"lkc-favicon\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/www.google.com\/s2\/favicons?domain=social.msdn.microsoft.com\" alt=\"\" width=\"16\" height=\"16\" \/><\/div><div class=\"lkc-domain\">social.msdn.microsoft.com<\/div><\/div><div class=\"lkc-content\"><figure class=\"lkc-thumbnail\"><img decoding=\"async\" class=\"lkc-thumbnail-img\" src=\"https:\/\/s.wordpress.com\/mshots\/v1\/https%3A%2F%2Fsocial.msdn.microsoft.com%2FForums%2Fja-jp%2Fofficesupportteamja%2Fthread%2F0d9c6273-bade-4f6a-a0de-5adb748d15eb?w=100\" width=\"100px\" height=\"108px\" alt=\"\" \/><\/figure><div class=\"lkc-title\">Office &#12458;&#12540;&#12488;&#12513;&#12540;&#12471;&#12519;&#12531;&amp;#1239...<\/div><div class=\"lkc-url\" title=\"https:\/\/social.msdn.microsoft.com\/Forums\/ja-jp\/officesupportteamja\/thread\/0d9c6273-bade-4f6a-a0de-5adb748d15eb\">https:\/\/social.msdn.microsoft.com\/Forums\/ja-jp\/officesupportteamja\/thread\/0d9c6273-bade-4f6a-a0de-5adb748d15eb<\/div><\/div><div class=\"clear\"><\/div><\/div><\/a><\/div><\/div>\n","protected":false},"excerpt":{"rendered":"MSDN\u30d5\u30a9\u30fc\u30e9\u30e0\u306b\u300cPowerShell\u3092\u4f7f\u3063\u3066\u3001Word\u6587\u66f8\u306e\u900f\u304b\u3057\u6587\u5b57\u3092\u5909\u66f4\u3057\u305f\u3044\u300d\u3001\u3068\u306e\u8cea\u554f\u304c\u3042\u308a\u307e\u3057\u305f\u3002 \u3059\u3050\u306b\u601d\u3044\u3064\u304f\u306e\u306f\u3001PowerShell\u304b\u3089Word\u30a2\u30d7\u30ea\u30b1\u30fc\u30b7\u30e7\u30f3\u3092\u64cd\u4f5c\u3059\u308b\u3053\u3068\u3067\u3059\u304c\u3001\u4e0b\u8a18\u30b3\u30fc\u30c9\u306e\u3088 [&hellip;]","protected":false},"author":1,"featured_media":7127,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_jetpack_memberships_contains_paid_content":false,"footnotes":"","jetpack_publicize_message":"[PowerShell]Word\u6587\u66f8\u306e\u900f\u304b\u3057\u6587\u5b57\u3092\u5909\u66f4\u3059\u308b\u30b9\u30af\u30ea\u30d7\u30c8","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,49,94],"tags":[],"class_list":["post-12219","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-office","category-word-office","category-powershell"],"aioseo_notices":[],"jetpack_publicize_connections":[],"jetpack_featured_media_url":"https:\/\/www.ka-net.org\/blog\/wp-content\/uploads\/eyecatch-PowerShell.png","jetpack_shortlink":"https:\/\/wp.me\/p4UZZr-3b5","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/www.ka-net.org\/blog\/index.php?rest_route=\/wp\/v2\/posts\/12219","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=12219"}],"version-history":[{"count":1,"href":"https:\/\/www.ka-net.org\/blog\/index.php?rest_route=\/wp\/v2\/posts\/12219\/revisions"}],"predecessor-version":[{"id":12220,"href":"https:\/\/www.ka-net.org\/blog\/index.php?rest_route=\/wp\/v2\/posts\/12219\/revisions\/12220"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.ka-net.org\/blog\/index.php?rest_route=\/wp\/v2\/media\/7127"}],"wp:attachment":[{"href":"https:\/\/www.ka-net.org\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=12219"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.ka-net.org\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=12219"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.ka-net.org\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=12219"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}