从类似的Outlook 2010代码样本中,自定义Outlook 2016 Inspector Ribbon,vs 20



我希望为Office 2016开发一个基本的COM加载项(在全球范围内,对于其他某些办公室应用程序 - 最有可能,Excel,Word,PowerPoint,PowerPoint,Publisher& OneNote)但是在这种情况下,对于Outlook 2016,特别是在" insert"选项卡上的自定义组(" scanner's& cameras")中的" microsoft.outlook.mail.com.pose" Inspector" Inspector"功能添加" scanner"功能。

这是我的第一个VSTO COM加载项项目,我是代码的新手(但愿意学习者!)。我的广泛研究几乎没有逐步建议,但我已经确定了Microsoft的以下代码样本https://code.msdn.microsoft.com/office/vboutlookribbonxml-bc478854我希望适应(也许使用以下'scan'函数VB代码):

):
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

不幸的是,以上Microsoft Office Development Center示例代码适用于Office 2010和VS 2010,因此无法访问。

  1. 如何适应示例以与Office(Outlook)2016和VS 2015一起使用?

  2. 是否可以插入上述VB代码块(如书面)来替换样本上的测试按钮的代码,还是需要进一步调整?

您可以简单地将示例项目中的类复制到VS 2015项目中。示例项目正在使用一个项目模板作为VS 2015不支持的办公室版本,而Interop参考也将不同。

如果您要添加自定义功能区按钮,只需在"添加新项目对话框"中的Office/SharePoint节点中添加功能区(Visual Designer)项目(或功能区(XML)项目)。

<。

相关内容

  • 没有找到相关文章

最新更新