{"id":6710,"date":"2016-02-18T15:45:25","date_gmt":"2016-02-18T06:45:25","guid":{"rendered":"http:\/\/www.ka-net.org\/blog\/?p=6710"},"modified":"2016-02-18T15:45:53","modified_gmt":"2016-02-18T06:45:53","slug":"acrobat-xi%e3%82%92%e6%93%8d%e4%bd%9c%e3%81%97%e3%81%a6%e3%83%86%e3%82%ad%e3%82%b9%e3%83%88%e8%aa%8d%e8%ad%98%e6%93%8d%e4%bd%9c%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=6710","title":{"rendered":"Acrobat XI\u3092\u64cd\u4f5c\u3057\u3066\u30c6\u30ad\u30b9\u30c8\u8a8d\u8b58\u64cd\u4f5c\u3092\u884c\u3046VBA\u30de\u30af\u30ed"},"content":{"rendered":"<p>\u30de\u30af\u30ed\u304b\u3089Acrobat\u3092\u64cd\u4f5c\u3059\u308b\u5834\u5408\u300c<a href=\"\/\/www.ka-net.org\/blog\/?p=6637\" title=\"PDF\u30d5\u30a1\u30a4\u30eb\u4e0a\u306e\u30d5\u30a3\u30fc\u30eb\u30c9\u306e\u5024\u3092\u64cd\u4f5c\u3059\u308bVBA\u30de\u30af\u30ed | \u521d\u5fc3\u8005\u5099\u5fd8\u9332\" target=\"_blank\">PDF\u30d5\u30a1\u30a4\u30eb\u4e0a\u306e\u30d5\u30a3\u30fc\u30eb\u30c9\u306e\u5024\u3092\u64cd\u4f5c\u3059\u308bVBA\u30de\u30af\u30ed<\/a>\u300d\u306e\u3088\u3046\u306b\u3001Acrobat JavaScript\u3092\u7d4c\u7531\u3059\u308b\u3053\u3068\u3067\u3001\u69d8\u3005\u306a\u51e6\u7406\u3092\u5b9f\u884c\u3067\u304d\u307e\u3059\u3002<\/p>\n<p>\u3057\u304b\u3057\u3001\u30c6\u30ad\u30b9\u30c8\u8a8d\u8b58(OCR)\u51e6\u7406\u306fJavaScript\u3067\u5b9f\u884c\u3067\u304d\u306a\u3044\u3088\u3046\u3060\u3063\u305f\u306e\u3067\u3001UI Automation\u3067\u7121\u7406\u3084\u308a\u753b\u9762\u64cd\u4f5c\u3092\u3057\u3066\u307f\u307e\u3057\u305f\u3002<\/p>\n<pre class=\"brush: vb; title: ; notranslate\" title=\"\">'UIAutomationClient(UIAutomationCore.dll)\u8981\u53c2\u7167\r\nOption Explicit\r\n\r\nPrivate Declare Function FindWindowEx Lib &quot;user32&quot; Alias &quot;FindWindowExA&quot; ( _\r\n  ByVal hWndParent As Long, _\r\n  ByVal hWndChildAfter As Long, _\r\n  ByVal lpszClass As String, _\r\n  ByVal lpszWindow As String) As Long\r\nPrivate Declare Function PostMessage Lib &quot;user32&quot; Alias &quot;PostMessageA&quot; ( _\r\n  ByVal hWnd As Long, _\r\n  ByVal wMsg As Long, _\r\n  ByVal wParam As Long, _\r\n  ByVal lParam As Long) As Long\r\nPrivate Declare Sub Sleep Lib &quot;kernel32&quot; (ByVal dwMilliseconds As Long)\r\n\r\nPrivate Const WM_KEYDOWN = &amp;H100\r\nPrivate Const WM_KEYUP = &amp;H101\r\n\r\nPublic Sub Sample()\r\n'Acrobat XI\u3092\u64cd\u4f5c\u3057\u3066\u30c6\u30ad\u30b9\u30c8\u8a8d\u8b58\u64cd\u4f5c\u3092\u884c\u3046\u30de\u30af\u30ed\r\n'\u203b \u4ed6\u306e\u30d0\u30fc\u30b8\u30e7\u30f3\u306eAcrobat\u3067\u306f\u5b9f\u884c\u4e0d\u53ef\r\n  Dim appAcrobat As Object\r\n  Dim avdoc As Object\r\n  Dim uiAuto As CUIAutomation\r\n  Dim elmAcrobat As IUIAutomationElement\r\n  Dim elmMenuBar As IUIAutomationElement\r\n  Dim elmTagDialog As IUIAutomationElement\r\n  Dim elmCancelButton As IUIAutomationElement\r\n  Dim elmViewMenu As IUIAutomationElement\r\n  Dim elmViewMenu2 As IUIAutomationElement\r\n  Dim elmToolMenu As IUIAutomationElement\r\n  Dim elmToolMenu2 As IUIAutomationElement\r\n  Dim elmRecMenu As IUIAutomationElement\r\n  Dim elmRecTree As IUIAutomationElement\r\n  Dim elmTreeChild As IUIAutomationElement\r\n  Dim elmRecButton As IUIAutomationElement\r\n  Dim elmRecDialog As IUIAutomationElement\r\n  Dim elmAllPagesButton As IUIAutomationElement\r\n  Dim elmOKButton As IUIAutomationElement\r\n  Dim exptn As IUIAutomationExpandCollapsePattern\r\n  Dim iptn As IUIAutomationInvokePattern\r\n  Dim hAcrobat As Long\r\n  Dim hAVScrollView As Long\r\n  Const PDSaveFull = &amp;H1\r\n  Const FilePath As String = &quot;C:\\Test\\OCR.pdf&quot;\r\n  Const SaveFilePath As String = &quot;C:\\Test\\OCR2.pdf&quot;\r\n  \r\n  'Acrobat\u8d77\u52d5\r\n  Set appAcrobat = CreateObject(&quot;AcroExch.App&quot;)\r\n  Set avdoc = CreateObject(&quot;AcroExch.AVDoc&quot;)\r\n  avdoc.Open FilePath, &quot;&quot;\r\n  appAcrobat.Show\r\n  \r\n  hAcrobat = FindWindowEx(0, 0, &quot;AcrobatSDIWindow&quot;, vbNullString)\r\n  If hAcrobat = 0 Then Exit Sub\r\n  Set uiAuto = New CUIAutomation\r\n  Set elmAcrobat = uiAuto.ElementFromHandle(ByVal hAcrobat)\r\n  If elmAcrobat Is Nothing Then Exit Sub\r\n  Set elmMenuBar = GetElement(uiAuto, _\r\n                              elmAcrobat, _\r\n                              UIA_NamePropertyId, _\r\n                              &quot;\u30a2\u30d7\u30ea\u30b1\u30fc\u30b7\u30e7\u30f3&quot;, _\r\n                              UIA_MenuBarControlTypeId)\r\n  If elmMenuBar Is Nothing Then Exit Sub\r\n  \r\n  '&#x5B;\u30bf\u30b0\u4ed8\u3051\u3055\u308c\u3066\u3044\u306a\u3044\u6587\u66f8\u306e\u8aad\u307f\u4e0a\u3052]\u30c0\u30a4\u30a2\u30ed\u30b0\u304c\u8868\u793a\u3055\u308c\u305f\u3089\u9589\u3058\u308b\r\n  Sleep 1000\r\n  Set elmTagDialog = GetElement(uiAuto, _\r\n                                uiAuto.GetRootElement, _\r\n                                UIA_NamePropertyId, _\r\n                                &quot;\u30bf\u30b0\u4ed8\u3051\u3055\u308c\u3066\u3044\u306a\u3044\u6587\u66f8\u306e\u8aad\u307f\u4e0a\u3052&quot;, _\r\n                                UIA_WindowControlTypeId)\r\n  If Not elmTagDialog Is Nothing Then\r\n    Set elmCancelButton = GetElement(uiAuto, _\r\n                                     elmTagDialog, _\r\n                                     UIA_NamePropertyId, _\r\n                                     &quot;\u30ad\u30e3\u30f3\u30bb\u30eb(C)&quot;, _\r\n                                     UIA_ButtonControlTypeId)\r\n    If Not elmCancelButton Is Nothing Then\r\n      Set iptn = elmCancelButton.GetCurrentPattern(UIA_InvokePatternId)\r\n      iptn.Invoke\r\n    End If\r\n  End If\r\n  \r\n  '&#x5B;\u8868\u793a]\u30e1\u30cb\u30e5\u30fc\u304b\u3089&#x5B;\u30c6\u30ad\u30b9\u30c8\u8a8d\u8b58]\u8868\u793a\r\n  Set elmViewMenu = GetElement(uiAuto, _\r\n                               elmMenuBar, _\r\n                               UIA_NamePropertyId, _\r\n                               &quot;\u8868\u793a(V)&quot;, _\r\n                               UIA_MenuItemControlTypeId)\r\n  If elmViewMenu Is Nothing Then Exit Sub\r\n  Set exptn = elmViewMenu.GetCurrentPattern(UIA_ExpandCollapsePatternId)\r\n  exptn.Expand\r\n  Do\r\n    Set elmViewMenu2 = uiAuto.RawViewWalker.GetFirstChildElement(elmAcrobat)\r\n    Sleep 100\r\n    DoEvents\r\n  Loop Until elmViewMenu2.CurrentName = &quot;\u8868\u793a(V)&quot;\r\n  Set elmToolMenu = GetElement(uiAuto, _\r\n                               elmViewMenu2, _\r\n                               UIA_NamePropertyId, _\r\n                               &quot;\u30c4\u30fc\u30eb(T)&quot;, _\r\n                               UIA_MenuItemControlTypeId)\r\n  If elmToolMenu Is Nothing Then Exit Sub\r\n  Set exptn = elmToolMenu.GetCurrentPattern(UIA_ExpandCollapsePatternId)\r\n  exptn.Expand\r\n  Do\r\n    Set elmToolMenu2 = uiAuto.RawViewWalker.GetFirstChildElement(elmAcrobat)\r\n    Sleep 100\r\n    DoEvents\r\n  Loop Until elmToolMenu2.CurrentName = &quot;\u30c4\u30fc\u30eb(T)&quot;\r\n  Set elmRecMenu = GetElement(uiAuto, _\r\n                              elmToolMenu2, _\r\n                              UIA_NamePropertyId, _\r\n                              &quot;\u30c6\u30ad\u30b9\u30c8\u8a8d\u8b58(T)&quot;, _\r\n                              UIA_MenuItemControlTypeId)\r\n  If elmRecMenu Is Nothing Then Exit Sub\r\n  Set iptn = elmRecMenu.GetCurrentPattern(UIA_InvokePatternId)\r\n  iptn.Invoke\r\n  \r\n  '&#x5B;\u30c6\u30ad\u30b9\u30c8\u8a8d\u8b58]\u30c4\u30ea\u30fc\u9805\u76ee\u53d6\u5f97\r\n  Do\r\n    Set elmRecTree = GetElement(uiAuto, _\r\n                                elmAcrobat, _\r\n                                UIA_NamePropertyId, _\r\n                                &quot;\u30c6\u30ad\u30b9\u30c8\u8a8d\u8b58&quot;, _\r\n                                UIA_TreeItemControlTypeId)\r\n    Set elmTreeChild = uiAuto.RawViewWalker.GetFirstChildElement(elmRecTree)\r\n    Sleep 100\r\n    DoEvents\r\n  Loop Until elmTreeChild.GetCurrentPropertyValue(UIA_LegacyIAccessibleRolePropertyId) = &amp;HA\r\n  hAVScrollView = FindWindowEx(hAcrobat, 0, &quot;AVL_AVView&quot;, &quot;AVScrollView&quot;)\r\n  \r\n  '&#x5B;\u3053\u306e\u30d5\u30a1\u30a4\u30eb\u5185]\u30dc\u30bf\u30f3\u30d5\u30a9\u30fc\u30ab\u30b9\u2192Enter\u30ad\u30fc\u3067\u5b9f\u884c\r\n  Do\r\n    Set elmRecButton = GetElement(uiAuto, _\r\n                                  elmTreeChild, _\r\n                                  UIA_HelpTextPropertyId, _\r\n                                  &quot;\u3053\u306e\u30d5\u30a1\u30a4\u30eb\u5185\u306e\u30c6\u30ad\u30b9\u30c8\u3092\u8a8d\u8b58&quot;, _\r\n                                  UIA_ButtonControlTypeId)\r\n    Sleep 100\r\n    DoEvents\r\n  Loop While elmRecButton Is Nothing\r\n  If elmRecButton Is Nothing Then Exit Sub\r\n  elmRecButton.SetFocus\r\n  PostMessage hAVScrollView, WM_KEYDOWN, vbKeyReturn, 0\r\n  PostMessage hAVScrollView, WM_KEYUP, vbKeyReturn, 0\r\n  \r\n  '&#x5B;\u30c6\u30ad\u30b9\u30c8\u8a8d\u8b58]\u30c0\u30a4\u30a2\u30ed\u30b0\u64cd\u4f5c\r\n  Do\r\n    Set elmRecDialog = GetElement(uiAuto, _\r\n                                  elmAcrobat, _\r\n                                  UIA_NamePropertyId, _\r\n                                  &quot;\u30c6\u30ad\u30b9\u30c8\u8a8d\u8b58&quot;, _\r\n                                  UIA_WindowControlTypeId)\r\n    Sleep 100\r\n    DoEvents\r\n  Loop While elmRecDialog Is Nothing\r\n  If elmRecDialog Is Nothing Then Exit Sub\r\n  Set elmAllPagesButton = GetElement(uiAuto, _\r\n                                     elmRecDialog, _\r\n                                     UIA_NamePropertyId, _\r\n                                     &quot;\u3059\u3079\u3066\u306e\u30da\u30fc\u30b8(A)&quot;, _\r\n                                     UIA_RadioButtonControlTypeId)\r\n  If elmAllPagesButton Is Nothing Then Exit Sub\r\n  Set iptn = elmAllPagesButton.GetCurrentPattern(UIA_InvokePatternId)\r\n  iptn.Invoke\r\n  Set elmOKButton = GetElement(uiAuto, _\r\n                               elmRecDialog, _\r\n                               UIA_NamePropertyId, _\r\n                               &quot;OK&quot;, _\r\n                               UIA_ButtonControlTypeId)\r\n  If elmOKButton Is Nothing Then Exit Sub\r\n  Set iptn = elmOKButton.GetCurrentPattern(UIA_InvokePatternId)\r\n  iptn.Invoke '&#x5B;OK]\u30dc\u30bf\u30f3\u30af\u30ea\u30c3\u30af\r\n  '\u203b \u30c6\u30ad\u30b9\u30c8\u8a8d\u8b58\u51e6\u7406\u5f85\u3061\u306fAcrobat\u306b\u307e\u304b\u305b\u308b\r\n  \r\n  'Acrobat\u7d42\u4e86\r\n  avdoc.GetPDDoc.Save PDSaveFull, SaveFilePath\r\n  avdoc.Close 1\r\n  appAcrobat.Hide: appAcrobat.Exit\r\n  \r\n  MsgBox &quot;\u51e6\u7406\u304c\u7d42\u4e86\u3057\u307e\u3057\u305f\u3002&quot;, vbInformation + vbSystemModal\r\nEnd Sub\r\n\r\nPrivate Function GetElement(ByVal uiAuto As CUIAutomation, _\r\n                            ByVal elmParent As IUIAutomationElement, _\r\n                            ByVal propertyId As Long, _\r\n                            ByVal propertyValue As Variant, _\r\n                            Optional ByVal ctrlType As Long = 0) As IUIAutomationElement\r\n  Dim cndFirst As IUIAutomationCondition\r\n  Dim cndSecond As IUIAutomationCondition\r\n  \r\n  Set cndFirst = uiAuto.CreatePropertyCondition( _\r\n                   propertyId, _\r\n                   propertyValue _\r\n                 )\r\n  If ctrlType &lt;&gt; 0 Then\r\n    Set cndSecond = uiAuto.CreatePropertyCondition( _\r\n                      UIA_ControlTypePropertyId, _\r\n                      ctrlType _\r\n                    )\r\n    Set cndFirst = uiAuto.CreateAndCondition( _\r\n                     cndFirst, _\r\n                     cndSecond _\r\n                   )\r\n  End If\r\n  Set GetElement = elmParent.FindFirst(TreeScope_Subtree, cndFirst)\r\nEnd Function<\/pre>\n<p>\u30fb\u30fb\u30fb\u5f8c\u534a\u3001\u3082\u3046\u98fd\u304d\u307e\u3057\u305f\u3002<br \/>\n\u7121\u7406\u3084\u308a\u904e\u304e\u308b\u306e\u3067\u3001<span style=\"color: #ff0000; font-weight: bold;\">\u5b9f\u7528\u6027\u306f\u6b63\u76f4\u7686\u7121<\/span>\u3060\u3068\u601d\u3044\u307e\u3059\u3002<\/p>\n<p>\u3053\u3093\u306a\u30b3\u30fc\u30c9\u3067\u51e6\u7406\u3092\u81ea\u52d5\u5316\u3059\u308b\u3088\u308a\u306f\u3001Acrobat(Pro)\u306e\u6a19\u6e96\u6a5f\u80fd\u3067\u3042\u308b\u30a2\u30af\u30b7\u30e7\u30f3(\u30d0\u30c3\u30c1)\u6a5f\u80fd\u3092\u4f7f\u7528\u3059\u308b\u3053\u3068\u3092\u304a\u85a6\u3081\u3057\u307e\u3059\u3002<br \/>\n(\u30b3\u30fc\u30c9\u3092\u8f09\u305b\u3066\u304a\u3044\u3066\u306a\u3093\u3067\u3059\u304c\u30fb\u30fb\u30fb)<\/p>\n","protected":false},"excerpt":{"rendered":"\u30de\u30af\u30ed\u304b\u3089Acrobat\u3092\u64cd\u4f5c\u3059\u308b\u5834\u5408\u300cPDF\u30d5\u30a1\u30a4\u30eb\u4e0a\u306e\u30d5\u30a3\u30fc\u30eb\u30c9\u306e\u5024\u3092\u64cd\u4f5c\u3059\u308bVBA\u30de\u30af\u30ed\u300d\u306e\u3088\u3046\u306b\u3001Acrobat JavaScript\u3092\u7d4c\u7531\u3059\u308b\u3053\u3068\u3067\u3001\u69d8\u3005\u306a\u51e6\u7406\u3092\u5b9f\u884c\u3067\u304d\u307e\u3059\u3002 \u3057\u304b\u3057\u3001\u30c6\u30ad\u30b9\u30c8\u8a8d\u8b58(OCR)\u51e6 [&hellip;]","protected":false},"author":1,"featured_media":7111,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_jetpack_memberships_contains_paid_content":false,"footnotes":"","jetpack_publicize_message":"\u5b9f\u7528\u6027\u306e\u7121\u3044\u5b9f\u9a13\u7684\u30b3\u30fc\u30c9\u3067\u3059\u3002 [Acrobat XI\u3092\u64cd\u4f5c\u3057\u3066\u30c6\u30ad\u30b9\u30c8\u8a8d\u8b58\u64cd\u4f5c\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,136],"tags":[],"class_list":["post-6710","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-office","category-excel-office","category-word-office","category-powerpoint","category-acrobat"],"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-1Ke","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/www.ka-net.org\/blog\/index.php?rest_route=\/wp\/v2\/posts\/6710","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=6710"}],"version-history":[{"count":1,"href":"https:\/\/www.ka-net.org\/blog\/index.php?rest_route=\/wp\/v2\/posts\/6710\/revisions"}],"predecessor-version":[{"id":6711,"href":"https:\/\/www.ka-net.org\/blog\/index.php?rest_route=\/wp\/v2\/posts\/6710\/revisions\/6711"}],"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=6710"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.ka-net.org\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=6710"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.ka-net.org\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=6710"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}