Graham Mayor

... helping to ease the lives of Microsoft Word users.

Many people access the material from this web site daily. Most just take what they want and run. That's OK, provided they are not selling on the material as their own; however if your productivity gains from the material you have used, a donation from the money you have saved would help to ensure the continued availability of this resource. Click the appropriate button above to access PayPal.

Scanning into Word 2007/2010/2013

Word 2007/2010

There have been numerous complaints from Word 2003 users who have upgraded to Word 2007/2010 that the tool that allows documents to be scanned as images, directly into Word, appears to be missing in the newer versions. In fact it is not missing, but very well hidden, however, fellow MVP Herb Tyson spotted that the ancient WordBasic command to call the old dialog has been retained in the application, and so with a little juggling and the aid of a macro, it is possible to add the command to the QAT (Quick Access Toolbar) thus restoring the ability to scan into these versions.

The macro code is simplicity itself

Sub InsertFromScanner()
On Error Resume Next
WordBasic.InsertImagerScan
End Sub

Clicking the button (or running the macro) produces the following familiar dialog:

Word 2007, 2010 & 2013

Simple though the above is for Word 2007 and 2010, it doesn't work with Word 2013 as the all important WordBasic command has been removed from Word 2013 VBA. Fortunately all is not lost. A more complex approach will do the job.

The following macros include alternative code samples for Excel and Outlook e-mail messages.

The method uses the WIA interface which requires a reference to the Microsoft Windows Image Acquisition object library to be set in vba - tools > references.

The macro displays the WIA dialog

Option Explicit

Public Declare Function SHGetSpecialFolderLocation _
Lib "shell32" (ByVal hwnd As Long, _
ByVal nFolder As Long, ppidl As Long) As Long

Public Declare Function SHGetPathFromIDList _
Lib "shell32" Alias "SHGetPathFromIDListA" _
(ByVal pidl As Long, ByVal pszPath As String) As Long

Public Declare Sub CoTaskMemFree Lib "ole32" (ByVal pvoid As Long)

Public Const CSIDL_LOCAL_APPDATA = &H1C '<user name>\Local Settings\Application Data
Public Const MAX_PATH = 260
Public Const NOERROR = 0


Public Function TempFolder(ByVal lngFolder As Long) As String
Dim lngPidlFound As Long
Dim lngFolderFound As Long
Dim lngPidl As Long
Dim strPath As String

strPath = Space(MAX_PATH)
lngPidlFound = SHGetSpecialFolderLocation(0, lngFolder, lngPidl)
If lngPidlFound = NOERROR Then
lngFolderFound = SHGetPathFromIDList(lngPidl, strPath)
If lngFolderFound Then
TempFolder = Left$(strPath, _
InStr(1, strPath, vbNullChar) - 1)
End If
End If
CoTaskMemFree lngPidl
End Function


Sub Scan()
'Based on a macro by Günter Born www.borncity.de blog.borncity.com
'Requires a reference to Microsoft Windows Image Acquisition Object Library
' On Error Resume Next
Dim objCommonDialog As WIA.CommonDialog
Dim objImage As WIA.ImageFile
Dim strPath As String
Set objCommonDialog = New WIA.CommonDialog
Set objImage = objCommonDialog.ShowAcquireImage
strPath = SpecFolder(&H1C) & "\Temp\TempScan.jpg" ' set temporary file location

If Not objImage Is Nothing Then
objImage.SaveFile strPath ' save into temporary file
'Insertion alternatives ++++++++++++++
Selection.InlineShapes.AddPicture strPath ' Insert in Word Document
'ActiveSheet.Pictures.Insert(strPath).Select 'Insert in Excel
'If TypeName(ActiveWindow) = "Inspector" Then 'Insert into Outlook message
' If ActiveInspector.IsWordMail And ActiveInspector.EditorType = olEditorWord Then
' ActiveInspector.WordEditor.Application.Selection.InlineShapes.AddPicture strPath
' End If
'End If
'+++++++++++++++++++++++++++++++++++++
Set objImage = Nothing
End If
If Not Dir(strPath) = vbNullString Then Kill strPath 'Remove the temporary file
Set objCommonDialog = Nothing
End Sub


Public Function SpecFolder(ByVal lngFolder As Long) As String
Dim lngPidlFound As Long
Dim lngFolderFound As Long
Dim lngPidl As Long
Dim strPath As String

strPath = Space(MAX_PATH)
lngPidlFound = SHGetSpecialFolderLocation(0, lngFolder, lngPidl)
If lngPidlFound = NOERROR Then
lngFolderFound = SHGetPathFromIDList(lngPidl, strPath)
If lngFolderFound Then
SpecFolder = Left$(strPath, _
InStr(1, strPath, vbNullChar) - 1)
End If
End If
CoTaskMemFree lngPidl
End Function

 

If you don't know to employ the codes used on this page or add the command button to the QAT (Quick Access Toolbar), see - http://www.gmayor.com/installing_macro.htm

 

 

Scan into Word

When you scan into Word, the imported text is in the form of an uneditable graphic. If you want editable text, you must use OCR software.

Office 2010 for example includes a rudimentary OCR function as part of One Note that can be used, but for better results you will need a third party product. My personal favourite is ABBYY Finereader.