I am looking to develop a basic com add-in for Office 2016 (perhaps globally for some of the other office apps - most likely, Excel, Word, PowerPoint, Publisher & OneNote) but in this instance for Outlook 2016 and specifically to add an 'Insert from Scanner" function to the "Microsoft.Outlook.Mail.Compose" Inspector Ribbon in a custom group ("Scanner's & Cameras") on it's "Insert" Tab.
This is my first VSTO com add-in project and I am new to code (but a willing learner!). My extensive research has gleaned little in step-by-step advice but I have identified the following code sample from microsoft https://code.msdn.microsoft.com/office/VBOutlookRibbonXml-bc478854 which I had hoped to adapt (perhaps utilising the following 'scan' function vb code):
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(control As IRibbonControl)
Const olEditorWord = 4
Dim objCommonDialog As WIA.CommonDialog
Dim objImage As WIA.ImageFile
Dim strDateiname As String
Dim ActiveObject As Object, ActiveTarget As Object
' 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
'Insert the picture into the office application:
Select Case Trim$(Replace$(Application.Name, "Microsoft", ""))
Case "Excel"
Set ActiveObject = CallByName(Application, "ActiveSheet", VbGet)
Set ActiveTarget = CallByName(Application, "ActiveCell", VbGet)
If ActiveTarget Is Nothing Then
'Insert into a chart, etc.
ActiveObject.Shapes.AddPicture _
strDateiname, False, True, 0, 0, -1, -1
Else
'Insert into a sheet at the active cell
ActiveObject.Shapes.AddPicture _
strDateiname, False, True, ActiveTarget.Left, ActiveTarget.Top, -1, -1
End If
Case "Outlook"
Set ActiveObject = CallByName(Application, "ActiveInspector", VbGet)
If ActiveObject Is Nothing Then
MsgBox "Create a new mail and try again"
Exit Sub
End If
With ActiveObject
If .IsWordMail And .EditorType = olEditorWord Then
.WordEditor.Application.Selection.InlineShapes.AddPicture strDateiname
End If
End With
Case "PowerPoint"
Set ActiveObject = CallByName(ActiveWindow, "View", VbGet)
ActiveObject.Slide.Shapes.AddPicture strDateiname, False, True, 0, 0, -1, -1
Case "Publisher"
Set ActiveObject = CallByName(Application, "ActiveDocument", VbGet)
ActiveObject.ActiveView.ActivePage.Shapes.AddPicture strDateiname, False, True, 0, 0, -1, -1
Case "Word"
Set ActiveObject = CallByName(Application, "Selection", VbGet)
ActiveObject.InlineShapes.AddPicture strDateiname
End Select
End If
End Sub
Unfortunately the above Microsoft Office Development Centre Sample code is for Office 2010 and VS 2010 and so can't be accessed.
How can I adapt the sample for use with Office (Outlook) 2016 and VS 2015?
Can the above VB code block be inserted (as written) to replace the code of one the test buttons on the sample, or will it require adapting further?