如何使用 Lotus 脚本关闭文件资源管理器 window
How to close file explorer window using lotus script
我正在编写代码以使用 Lotus Notes 中的免费文件导出 CSV 代码工作正常,但我在关闭文件资源管理器时遇到问题 window。场景是,如果我现在不需要导出并且不知不觉地单击导出按钮,它会要求打开文件资源管理器 window。文件资源管理器 window 它没有关闭,它要求输入文件名及其循环,直到我给出文件名。
我的代码:
Sub Initialize
Dim ws As New NotesUIWorkspace
Dim session As New NotesSession
Dim source As NotesUIDocument
Dim db As NotesDatabase
Dim dc As NotesDocumentCollection
Dim doc As NotesDocument
Dim headerString As String
Dim header As Variant
Dim sno As Variant
Dim vw As NotesView
Dim flag As Boolean
REM Get selected document
Set db = session.CurrentDatabase
Set dc = db.UnprocessedDocuments
Set dc=db.Alldocuments
Set doc = dc.GetFirstDocument
sno=0
Dim count As Variant
count=0
While Not doc Is Nothing
filenames = ws.SaveFileDialog( _
False,"File name",, "E:\samp", ".csv")
If Not(IsEmpty(filenames)) Then
REM Write Body item to file
fileNum% = FreeFile()
Open filenames(0) For Output As fileNum%
headerString ="S.No,UNID,NAME,STATUS,TIME"
header = Split(UCase(headerString),",")
Print #fileNum%, headerString
Do Until doc Is Nothing
If (CStr(doc.Getitemvalue("Status")(0)="Accepted")) Then
sno=sno+1
d=sno+","+doc.Universalid+","+doc.Getitemvalue("Uname")(0)+","+doc.getitemvalue("Status")(0)+","+doc.Getitemvalue("Time")(0)
Print #fileNum%,d
flag=0
Else
flag=1
End If
Set doc = dc.Getnextdocument(doc)
count=count+1
Loop
Else
End If
Wend
If (flag="1") Then
MsgBox"no documents were accepted"
Else
MsgBox "Document exported successfully"
End If
Close fileNum%
End Sub
If Not(IsEmpty(filenames)) Then
'<code removed for brevity>
Else
set doc = nothing
End If
像上面一样放入else语句,这样当你没有发送文件名时,doc被设置为nothing并且while循环退出。
您的代码不必要地复杂,并且有一个根本不需要的额外循环:您有一个外部“while”- 什么都不做的循环和一个内部“Do until”- 真正执行的循环循环。
只需将外层循环替换为 If,那么只会提示一次...
而不是
While Not doc Is Nothing
filenames = ws.SaveFileDialog( _
False,"File name",, "E:\samp", ".csv")
If Not(IsEmpty(filenames)) Then
...
Do Until doc Is Nothing
...
Loop
End If
Wend
随便写
If Not doc Is Nothing
filenames = ws.SaveFileDialog( _
False,"File name",, "E:\samp", ".csv")
If Not(IsEmpty(filenames)) Then
...
Do Until doc Is Nothing
...
Loop
End If
End If
我正在编写代码以使用 Lotus Notes 中的免费文件导出 CSV 代码工作正常,但我在关闭文件资源管理器时遇到问题 window。场景是,如果我现在不需要导出并且不知不觉地单击导出按钮,它会要求打开文件资源管理器 window。文件资源管理器 window 它没有关闭,它要求输入文件名及其循环,直到我给出文件名。
我的代码:
Sub Initialize
Dim ws As New NotesUIWorkspace
Dim session As New NotesSession
Dim source As NotesUIDocument
Dim db As NotesDatabase
Dim dc As NotesDocumentCollection
Dim doc As NotesDocument
Dim headerString As String
Dim header As Variant
Dim sno As Variant
Dim vw As NotesView
Dim flag As Boolean
REM Get selected document
Set db = session.CurrentDatabase
Set dc = db.UnprocessedDocuments
Set dc=db.Alldocuments
Set doc = dc.GetFirstDocument
sno=0
Dim count As Variant
count=0
While Not doc Is Nothing
filenames = ws.SaveFileDialog( _
False,"File name",, "E:\samp", ".csv")
If Not(IsEmpty(filenames)) Then
REM Write Body item to file
fileNum% = FreeFile()
Open filenames(0) For Output As fileNum%
headerString ="S.No,UNID,NAME,STATUS,TIME"
header = Split(UCase(headerString),",")
Print #fileNum%, headerString
Do Until doc Is Nothing
If (CStr(doc.Getitemvalue("Status")(0)="Accepted")) Then
sno=sno+1
d=sno+","+doc.Universalid+","+doc.Getitemvalue("Uname")(0)+","+doc.getitemvalue("Status")(0)+","+doc.Getitemvalue("Time")(0)
Print #fileNum%,d
flag=0
Else
flag=1
End If
Set doc = dc.Getnextdocument(doc)
count=count+1
Loop
Else
End If
Wend
If (flag="1") Then
MsgBox"no documents were accepted"
Else
MsgBox "Document exported successfully"
End If
Close fileNum%
End Sub
If Not(IsEmpty(filenames)) Then
'<code removed for brevity>
Else
set doc = nothing
End If
像上面一样放入else语句,这样当你没有发送文件名时,doc被设置为nothing并且while循环退出。
您的代码不必要地复杂,并且有一个根本不需要的额外循环:您有一个外部“while”- 什么都不做的循环和一个内部“Do until”- 真正执行的循环循环。
只需将外层循环替换为 If,那么只会提示一次...
而不是
While Not doc Is Nothing
filenames = ws.SaveFileDialog( _
False,"File name",, "E:\samp", ".csv")
If Not(IsEmpty(filenames)) Then
...
Do Until doc Is Nothing
...
Loop
End If
Wend
随便写
If Not doc Is Nothing
filenames = ws.SaveFileDialog( _
False,"File name",, "E:\samp", ".csv")
If Not(IsEmpty(filenames)) Then
...
Do Until doc Is Nothing
...
Loop
End If
End If