【发布时间】:2016-02-25 15:59:09
【问题描述】:
我想用 VBA 从 Lotus Notes 打开一个附件。 问题是我没有找到 Lotus Notes 的路径。
如果你能给我一个代码,我将非常感激,我如何在不硬编码的情况下打开这条路径。
这是不起作用的完整代码......
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)
结束函数 子 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
【问题讨论】:
-
请edit您的帖子包含实际的相关代码。 您的代码的屏幕截图是不行的。
-
重新修改代码:您不能使用 $File。如果要使用 body.EmbeddedObjects,则需要找到嵌入附件的富文本字段的名称。 $File 是一个特殊的对象,而不是富文本字段。使用 getFirstItem("body") 可能是正确的,但是您已经查看了表单,或者查看了文档属性对话框中的字段列表并找到了应用程序中使用的真实名称。即使这样也可能不起作用,因为有时附件没有保存在富文本字段中,在这种情况下,我在代码中给出的答案仍然适用:使用 objNotesDocument.EmbeddedObjects。
标签: excel vba lotus-notes