Hi Andreas,
Thanks a million.......you cracked it.......whooa!!
I recompiled my macro replacing my sub script with yours and it now works like a charm.
For the assistance of anybody else looking for a means of Scanning an Image/Document directly into Excel 2016 (64 Bit) and then assigning a Ribbon Button and/or Quick Action Toolbar to enact the function the complete Macro for Excel 2016 (64 Bit) is shown
below:
' Scan for Excel 2016 - 64 Bit
' Author: Günter Born www.borncity.de blog.borncity.com
' Implements a Scan function in Excel 2016
Private Declare PtrSafe 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 length of the path, just as big as possible
Dim FolderName As String ' Name of the folder
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()
Dim objCommonDialog As WIA.CommonDialog
Dim objImage As WIA.ImageFile
Dim strDateiname As String
' instantiate Scan WIA objects
Set objCommonDialog = New WIA.CommonDialog
Set objImage = objCommonDialog.ShowAcquireImage
strDateiname = Environ$("TEMP") & "\Scan.jpg" ' set temporary file
If Not objImage Is Nothing Then
If Dir(strDateiname) <> "" Then Kill strDateiname
objImage.SaveFile strDateiname 'save into temp file
DoEvents
ActiveSheet.Shapes.AddPicture _
strDateiname, False, True, ActiveCell.Left, ActiveCell.Top, -1, -1
End If
End Sub
==============================================================
........For Word 2016 (64 Bit)
' Scan for Word 2016 - 64 Bit
' Author: Günter Born www.borncity.de blog.borncity.com
' Implements a Scan function in Word 2016
Private Declare PtrSafe 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 length of the path, just as big as possible
Dim FolderName As String ' Name of the folder
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 2016
'
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
' strDateiname = "C:\Users\Public\Pictures" & "Scan.jpg"
If Not objImage Is Nothing Then
Kill strDateiname
objImage.SaveFile strDateiname ' save into temp file
Selection.InlineShapes.AddPicture strDateiname ' insert into document
Set objImage = Nothing
End If
Set objCommonDialog = Nothing
' MsgBox strDateiname ' test output
End Sub
============================================================
&..........For Outlook 2016 (64 Bit)
' Scan for Outlook 2016 - 64 Bit
' Author: Günter Born www.borncity.de blog.borncity.com
' Implements a Scan function in Outlook 2016
Private Declare PtrSafe 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 length of the path, just as big as possible
Dim FolderName As String ' Name of the folder
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 Outlook 2016
'Set a reference to Microsoft Windows Image Acquisition Library V 2.0
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 = Environ("TEMP") & "\TempScan.jpg" ' set temporary file
If Not objImage Is Nothing Then
objImage.SaveFile strPath ' save into temp file
On Error GoTo ErrHandler
If TypeName(ActiveWindow) = "Inspector" Then
If ActiveInspector.IsWordMail And ActiveInspector.EditorType = olEditorWord Then
ActiveInspector.WordEditor.Application.Selection.InlineShapes.AddPicture strPath ' insert in MESSAGE
End If
End If
Kill strPath
End If
lbl_Exit:
Set objImage = Nothing
Set objCommonDialog = Nothing
Exit Sub
ErrHandler:
Beep
Resume lbl_Exit
End Sub
=================================================================
Thanks Andreas......very much appreciated!! :)
Best Regards,
PC Pilot