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.
How it Works
The following instructions will show you how to create a scan button in Word 2013. The functionality wasn’t included in the product, but you can create your own.
Using this button invokes the dialog box shown below. A user may select the WIA device to obtain a photo.
After clicking OK, the WIA dialog box shown below will be visible. Here we see the scanner dialog box.
Using the Scan 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.
Implementing a macro for WIA control
How to implement this feature in Word 2013? The View tab contains the Macro button which may be used to invoke the Macros dialog box. The button create may be used to add a VBA macro.
At this point, you still don’t have a word object for scanning – you will have to make a change to the Type Libraries (Menu Tools, command References).
Locate the “Image Acquisition Library” type library and enable it by selecting it. This will be used to access the WIA interface.
VBA code to access the WIA interface
The following VBA code will access WIA, detect the temp folder and store the image there.
‘ Scan for Word 2013 ‘ Implements a Scan function in Word 2013 Private Declare Function GetTempPath Lib “kernel32″ Alias “GetTempPathA” (ByVal nBufferLength As Long, ByVal lpBuffer As String) As Long Private Function TempPath() As String Const MaxPathLen = 256 ‘ Max path length Dim FolderName As String ‘ Folder name Dim ReturnVar As Long ‘ Return Value FolderName = String(MaxPathLen, 0) ReturnVar = GetTempPath(MaxPathLen, FolderName) If ReturnVar <> 0 Then TempPath = Left(FolderName, InStr(FolderName, Chr(0)) – 1) Else TempPath = vbNullString End If End Function
Sub Scan() ‘ ‘ Scan Macro, to be invoked in Word ‘ On Error Resume Next Dim objCommonDialog As WIA.CommonDialog Dim objImage As WIA.ImageFile Dim strDateiname ‘ instantiate Scan WIA objects Set objCommonDialog = New WIA.CommonDialog Set objImage = objCommonDialog.ShowAcquireImage strDateiname = TempPath & “Scan.jpg” ‘ set temporary file If Not objImage Is Nothing Then Kill strDateiname objImage.SaveFile strDateiname ‘ save into temp file Selection.InlineShapes.AddPicture strDateiname ‘ insert in doc Set objImage = Nothing End If Set objCommonDialog = Nothing ‘ MsgBox strDateiname ‘ test output End Sub
The VBA code initiates a WIA.CommonDialog object and invokes the ShowAcquireImage method. The method returns the scan as an object. This will be stored temporarily and will be inserted into Word document file.
Add a scan button
This is the final step where you add the button that will do the scanning. Go to the insert tab and associate it with the VBA macro.
1. Right click the ribbon bar und select the command to change ribbon settings.
2. Select the entry “macro” in the left list of dialog box Word options.
3. Add a new group entry “Scan” to Insert tab and associate the macro from left list to this new group. Name it “Scan” and assign an appropriate image to this button.
After closing the dialog box, the new Scan button shall be working. You can download the code here in a zip file. It contains a Word *.docm file and a macro code file (.bas) ready to use. You can use the sample and copy the macro code to your Normal.dot file to make it available by default in new documents.