作成者カテゴリ 
公開
りん
02/15/2008 02:34 PM
クライアント
ノーツサーバノーツクライアントサーバOSクライアントOSネットワークプロトコル
6.x6.xWindows 2000 ServerWindows XP ProTCP/IP

添付ファイルの自動印刷について

お世話になります

LotusScript でフォームAの文書で入力された Code をキーにフォームBの文書を検索して、フォームBに添付されているファイルを印刷するという Windows API を使用したプログラムを作成しています
ファイルをクライアントに保存させたままにしたくないため、印刷が終わったらファイルを削除したいのですがうまくいきません
添付ファイルが Excel や Word の場合は印刷・削除まで正常に実行されるのですが、 PDF や TXT の場合にファイルがないというエラーが発生してしまい、印刷できません
ファイル削除の部分をコメントアウトすると正常に印刷されるので印刷のプログラムそのものは間違っていないと思われます

現在のプログラムは以下のようになっています

Declare Function GetDesktopWindow Lib "user32" ( ) As Long
Declare Function ShellExecute Lib "shell32.dll" Alias "ShellExecuteA" ( Byval hwnd As Long, Byval lpOperation As String, Byval lpFile As String, Byval lpParameters As String, Byval lpDirectory As String, Byval nShowCmd As Long ) As Long
Declare Function FindWindow Lib "user32" Alias "FindWindowA" (Byval lpClassName As String, Byval lpWindowName As String) As Long
Declare Function SendMessage Lib "user32" Alias "SendMessageA" (Byval hwnd As Long, Byval wMsg As Long, Byval wParam As Long, lParam As Long) As Long
Declare Function DeleteFile Lib "KERNEL32" Alias "DeleteFileA" (Byval lpFileName As String) As Long

Sub Click(Source As Button)

Dim ws As New NotesUIWorkspace
Dim uidoc As NotesUIDocument

Dim ss As New NotesSession
Dim db As NotesDatabase
Dim view As NotesView
Dim col As NotesDocumentCollection
Dim doc As NotesDocument
Dim rtitem As NotesRichTextItem

Dim folder As String

Set uidoc = ws.CurrentDocument

Set db = ss.CurrentDatabase
Set view = db.GetView ( "MainView" )
Set col = view.GetAllDocumentsByKey ( uidoc.FieldGetText ( "Code" ) , True )
If col.Count < 1 Then
Messagebox "コード " + uidoc.FieldGetText ( "Code" ) + " の文書はありませんでした"
Exit Sub
End If

folder = "C:\"

Set doc = col.GetFirstDocument
Do Until doc Is Nothing
Set rtitem = doc.GetFirstItem ( "File" )
If Not rtitem Is Nothing Then
Forall r In rtitem.EmbeddedObjects
If r.Type = EMBED_ATTACHMENT Then
Call r.ExtractFile ( folder + r.Name )
Call ShellExecute ( GetDesktopWindow , "Print" , folder + r.Name , Null , Null , SW_HIDE )
Call DeleteFile ( folder + r.Name )
End If
End Forall
End If
Set doc = col.GetNextDocument ( doc )
Loop

Call SendMessage ( FindWindow ( vbNullString , vbNullString ) , WM_CLOSE , 0 , 0 )

Messagebox "すべての印刷が完了しました"

End Sub

一番いいのは添付ファイルをクライアントに保存しないで直接印刷をしてしまうことなのですが
それは無理そうなので、このような形になりました

どなたかエラーの原因と回避方法等をご存知ないでしょうか?
どうぞ宜しくお願いいたします


[Previous Main Document]
添付ファイルの自動印刷について (りん) * 現在地 *
. . Re: 添付ファイルの自動印刷について (加納)
. . . . Re: 添付ファイルの自動印刷について (りん)
. . . . . . Re: 添付ファイルの自動印刷について (加納)
[Next Main Document]