{"id":13616,"date":"2013-02-04T23:46:29","date_gmt":"2013-02-04T21:46:29","guid":{"rendered":"http:\/\/www.borncity.com\/blog\/?p=13616"},"modified":"2024-02-04T21:25:06","modified_gmt":"2024-02-04T20:25:06","slug":"scanning-in-word-2013","status":"publish","type":"post","link":"https:\/\/borncity.com\/blog\/2013\/02\/04\/scanning-in-word-2013\/","title":{"rendered":"Scanning in Word 2013"},"content":{"rendered":"<p><img loading=\"lazy\" decoding=\"async\" style=\"margin: 0px 10px 0px 0px; display: inline;\" src=\"https:\/\/borncity.com\/blog\/wp-content\/uploads\/2012\/07\/Office1.jpg\" alt=\"\" width=\"55\" height=\"60\" align=\"left\" \/>[<a href=\"https:\/\/borncity.com\/blog\/2013\/02\/04\/scannen-in-word-2013-teil-1\/\">German edition<\/a>]Microsoft Office 2013 is shipped with new features, but some users are missing usability. For instance, a simple button to scan directly from Word 2013 is missing. Also old solutions won't work anymore. Therefore I've developed a solution, to add a scan option to Word 2013.<\/p>\n<p><!--more--><\/p>\n<h3>How it it shall work \u2026<\/h3>\n<p><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/ssl-vg03.met.vgwort.de\/na\/41715e0855df4fabbd4a50fe07884392\" alt=\"\" width=\"1\" height=\"1\" \/>I'm using a German Word 2013, so all screenshots are made by this version. My idea was to establish a button <em>Scan <\/em>within the Word 2013 ribbon bar (Tab <em>Insert<\/em>).<\/p>\n<p><a href=\"https:\/\/i.imgur.com\/ezQnyk8.jpg\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/i.imgur.com\/6Hup4Vh.jpg\" alt=\"\" width=\"560\" height=\"372\" \/><\/a><\/p>\n<p>Using this button invokes the dialog box shown below. A user may select the WIA device to obtain a photo.<\/p>\n<p><a href=\"https:\/\/i.imgur.com\/wSsY3S6.jpg\"><img decoding=\"async\" src=\"https:\/\/i.imgur.com\/wSsY3S6.jpg\" alt=\"\" \/><\/a><\/p>\n<p>After clicking <em>OK, <\/em>the WIA dialog box shown below will be visible. Here we see the scanner dialog box.<\/p>\n<p><a href=\"https:\/\/i.imgur.com\/ywuqcF8.jpg\"><img decoding=\"async\" src=\"https:\/\/i.imgur.com\/ywuqcF8.jpg\" alt=\"\" \/><\/a><\/p>\n<p>Using the <em>Scan <\/em>button obtains the scan from the connected device and inserts it into the Word document. Therefore it's required, that Windows supports WIA drivers and devices.<\/p>\n<h3>Implementing a macro for WIA control<\/h3>\n<p>How to implement this feature in Word 2013? The <em>View<\/em> tab contains the <em>Macro <\/em>button which may be used to invoke the <em>Macros <\/em>dialog box. The button <em>create <\/em>may be used to add a VBA macro.<\/p>\n<p><a href=\"https:\/\/i.imgur.com\/T7jrPjt.jpg\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/i.imgur.com\/T7jrPjt.jpg\" alt=\"\" width=\"640\" height=\"395\" \/><\/a><\/p>\n<p>After searching a while, I was not able to find a Word object to scan \u2013 and I wasn't successful to invoke OneNote scan button from Word. Therefore I inspected the Type-Libraries (Menu <em>Tools<\/em>, command <em>References<\/em>).<\/p>\n<p><a href=\"https:\/\/i.imgur.com\/LGHX8Mm.jpg\" target=\"_blank\" rel=\"noopener external noreferrer\" data-wpel-link=\"external\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone\" title=\"Scan-Objekt einbinden\" src=\"https:\/\/i.imgur.com\/LGHX8Mm.jpg\" alt=\"Scan-Objekt einbinden\" width=\"640\" height=\"395\" \/><\/a><\/p>\n<p>I found the \"Windwos Image Acquisition Library\" type library, that may be used to access the WIA interface.<\/p>\n<h3>VBA code to access the WIA interface<\/h3>\n<p>After identifying the WIA type library I made a short research and found some VBA code fragments to access WIA [1,2], deleting a file [3] and to detect the <em>Temp <\/em>folder [4] (used to store the temporary image file). Here is the VBA source code.<\/p>\n<p>' Scan for Word 2013<br \/>\n' Author: G\u00fcnter Born www.borncity.de blog.borncity.com<br \/>\n' Implements a Scan function in Word 2013<\/p>\n<p>Private Declare Function GetTempPath Lib \"kernel32\" Alias \"GetTempPathA\" (ByVal nBufferLength As Long, ByVal lpBuffer As String) As Long<\/p>\n<p>Private Function TempPath() As String<br \/>\nConst MaxPathLen = 256 ' Max path length<br \/>\nDim FolderName As String ' Folder name<br \/>\nDim ReturnVar As Long ' Return Value<br \/>\nFolderName = String(MaxPathLen, 0)<br \/>\nReturnVar = GetTempPath(MaxPathLen, FolderName)<br \/>\nIf ReturnVar &lt;&gt; 0 Then<br \/>\nTempPath = Left(FolderName, InStr(FolderName, Chr(0)) \u2013 1)<br \/>\nElse<br \/>\nTempPath = vbNullString<br \/>\nEnd If<br \/>\nEnd Function<\/p>\n<p>Sub Scan()<br \/>\n'<br \/>\n' Scan Macro, to be invoked in Word<br \/>\n'<br \/>\nOn Error Resume Next<br \/>\nDim objCommonDialog As <em>WIA.CommonDialog<\/em><br \/>\nDim objImage As WIA.ImageFile<br \/>\nDim strDateiname<br \/>\n' instantiate Scan WIA objects<br \/>\nSet objCommonDialog = New WIA.CommonDialog<br \/>\nSet objImage = objCommonDialog.ShowAcquireImage<br \/>\nstrDateiname = TempPath &amp; \"Scan.jpg\" ' set temporary file<br \/>\nIf Not objImage Is Nothing Then<br \/>\nKill strDateiname<br \/>\nobjImage.SaveFile strDateiname ' save into temp file<br \/>\nSelection.InlineShapes.AddPicture strDateiname ' insert in doc<br \/>\nSet objImage = Nothing<br \/>\nEnd If<br \/>\nSet objCommonDialog = Nothing<br \/>\n' MsgBox strDateiname\u00a0 ' test output<br \/>\nEnd Sub<\/p>\n<p>The VBA code initiates a <em>WIA.CommonDialog <\/em>object and invokes the <em>ShowAcquireImage <\/em>method. The method returns the scan as an object. This will be stored temporarily and will be inserted into Word document file.<\/p>\n<h3>Add a scan button<\/h3>\n<p>At least we need to add a <em>Scan<\/em> button at <em>Insert <\/em>tab and associate it with the VBA macro.<\/p>\n<p>1. Right click the ribbon bar und select the command to change ribbon settings.<\/p>\n<p>2. Select the entry \"macro\" in the left list of dialog box <em>Word options<\/em>.<\/p>\n<p>3. Add a new group entry \"Scan\" to <em>Insert <\/em>tab and associate the macro from left list to this new group. Name it \"Scan\" and assign an appropriate image to this button.<\/p>\n<p><a href=\"https:\/\/i.imgur.com\/ZhIN5qp.jpg\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/i.imgur.com\/ZhIN5qp.jpg\" alt=\"\" width=\"640\" height=\"386\" \/><\/a><\/p>\n<p>After closing the dialog box, the new Scan button shall be working. <a href=\"https:\/\/borncity.com\/blog\/wp-content\/uploads\/2013\/02\/Scan1.zip\">Here <\/a>is a download file <em>Scan1.zip<\/em>, containing a Word *.docm file and a macro code file (.bas) with a a ready to use solution. You may use the sample and copy the macro code to your Normal.dot file.<\/p>\n<p><strong>Links:<\/strong><br \/>\n1: <a href=\"https:\/\/web.archive.org\/web\/20140427113109\/http:\/\/social.msdn.microsoft.com:80\/Forums\/en-US\/dd81e87c-9687-49d6-a07a-17e669491e16\/operate-scanner-from-vba-in-excel?forum=isvvba\">Technet-Article<\/a><br \/>\n2: <a href=\"https:\/\/web.archive.org\/web\/20190322032547\/http:\/\/www.access-im-unternehmen.de:80\/index1.php?id=300&amp;BeitragID=419\">Scan in Access<\/a><br \/>\n3: <a href=\"https:\/\/web.archive.org\/web\/20190907180103\/http:\/\/www.office-loesung.de:80\/ftopic220661_0_0_asc.php\">Delete files in VBA<\/a><br \/>\n4: Detect temp folder<\/p>\n","protected":false},"excerpt":{"rendered":"<p>[German edition]Microsoft Office 2013 is shipped with new features, but some users are missing usability. For instance, a simple button to scan directly from Word 2013 is missing. Also old solutions won't work anymore. Therefore I've developed a solution, to &hellip; <a href=\"https:\/\/borncity.com\/blog\/2013\/02\/04\/scanning-in-word-2013\/\">Weiterlesen <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[4358,395,2659,2658],"class_list":["post-13616","post","type-post","status-publish","format-standard","hentry","category-allgemein","tag-office-2013","tag-scannen","tag-vba","tag-word-2013"],"_links":{"self":[{"href":"https:\/\/borncity.com\/blog\/wp-json\/wp\/v2\/posts\/13616","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/borncity.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/borncity.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/borncity.com\/blog\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/borncity.com\/blog\/wp-json\/wp\/v2\/comments?post=13616"}],"version-history":[{"count":0,"href":"https:\/\/borncity.com\/blog\/wp-json\/wp\/v2\/posts\/13616\/revisions"}],"wp:attachment":[{"href":"https:\/\/borncity.com\/blog\/wp-json\/wp\/v2\/media?parent=13616"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/borncity.com\/blog\/wp-json\/wp\/v2\/categories?post=13616"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/borncity.com\/blog\/wp-json\/wp\/v2\/tags?post=13616"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}