使用VBA从Lotus Notes打开附件

时间:2016-02-25 15:59:10

标签: excel vba lotus-notes

我想使用VBA从Lotus Notes打开附件。 问题是我没有从Lotus Notes中获取路径。

Error in Code

Lotus Notes File

如果你能给我一个代码,我将非常感谢,如何在没有硬编码的情况下打开这条路径。

以下是完整的代码,但不起作用......

Function OpenURL(URL As String, WindowState As W32_Window_State) As Boolean

'Opens passed URL with default application, or Error Code (<32) upon error

Dim lngHWnd As Long
Dim lngReturn As Long

lngReturn = ShellExecute(lngHWnd, "open", URL, vbNullString, _
vbNullString, WindowState)

OpenURL = (lngReturn > 32)

结束功能 Sub OpenLotusNotes()

Dim objNotesSession As Object
Dim objNotesFile As Object
Dim objNotesDocument As Object

Dim objNotesField As Object
Dim objNotesUIWorkSpace As Object
Dim objNotesView As Object



Set objNotesSession = CreateObject("Notes.NotesSession")
Set objNotesFile = objNotesSession.GETDATABASE("ATLAS40", "ACITF\PRODUCTION\USN\ePayable.nsf")
'("Server", "Datenbank")
Set objNotesUIWorkSpace = CreateObject("Notes.NotesUIWorkSpace")

Set i = Sheet1.Range("B20")

Dim DocNum As Variant
Dim DocName As Variant
Set objNotesView = objNotesFile.GetView("1.CheckView")
Set objNotesDocument = objNotesView.GetFirstDocument

Dim body As Variant


Dim ms As String
ms = ""

If Not objNotesDocument Is Nothing Then
    'initial set
    DocNum = objNotesDocument.InvoiceNumber
    DocName = objNotesDocument.InvoiceDocumentNumber
    Dim DocFound As Boolean

    DocFound = False

    While Not DocFound = True
        DocNum = objNotesDocument.InvoiceNumber
        DocName = objNotesDocument.InvoiceDocumentNumber



        If DocNum(0) = i Then
            ms = "You are about to open the attachement located in " & DocNum(0) & " " & DocName(0) & " in The Way we do things database from Database Server " & objNotesFile.server & " with Database File name " & objNotesFile.Filename & "."

            MsgBox (ms)
            DocFound = True

            Set body = objNotesDocument.getfirstitem("$FILE")

            'subject der mail ermitteln
            For Each obj In body.embeddedobjects

                'MsgBox (Environ("TEMP") & "\" & obj.Name)
                'MsgBox (obj.Name)
                Call obj.ExtractFile(Environ("TEMP") & "\" & obj.Name)
                OpenURL "file://" & Environ("TEMP") & "\" & obj.Name, Show_Maximized

            Next
        End If
        Set objNotesDocument = objNotesView.GetNextDocument(objNotesDocument)
    Wend
End If

1 个答案:

答案 0 :(得分:1)

您无法通过访问$ File项来打开文件,因此即使您使用了正确的语法(使用GetFirstItem(“$ File)),它仍然无效。

您需要使用objNotesDocument.EmbeddedObjects()这将返回NotesEmbeddedObject个对象的数组。如果文档中只有一个文件附件,则阵列中只有一个元素。您可以使用NotesEmbeddedObject类的ExtractFile方法将文件的副本保存到文件系统,然后您可以从那里打开它。