Function WriteFileHeader(expfilename As String) As Integer Dim filenum As Integer ' filehandle Dim tempdir As String ' temp directory on server Dim fname As String ' filename/filepath On Error Goto FErrorHandler ' setup filepath filenum = Freefile tempdir = Environ("Temp") fname = tempdir & "\" & expfilename ' kill existing file if exists Call KillExistingFile(fname) ' open up new file for write Open fname For Output As filenum ' return success as file handle WriteFileHeader = filenum Exit Function FErrorHandler: Print "(WriteFileHeader) Error. Info: " & Str(Err) & ": " & Error$ & " on line: " & Cstr(Erl) & "
" WriteFileHeader =0 Exit Function End Function Function WriteFileFooter(filehandle As Integer, db As NotesDatabase) As Integer ' closes open file Close filehandle ' return success WriteFileFooter=1 End Function Function WriteLine(linetext As String, sendflag As String, filehandlenum As Integer) As Integer ' writes a line either to file or browser depending on sendflag If (sendflag="1") Then Print # filehandlenum, linetext Else Print linetext End If End Function Function SendFile(db As NotesDatabase, sendtonms As Variant, fromnm As String, expfilename As String, subjectnm As String, _ deleteflag As Integer) As Integer ' sends created attachment file ' db - a valid db, needed to compose memo ' sendtonms - variant, could be one or list ' fromnm - who from ' expfilename - filename of attachment to attach ' subjectnm - subject/report name ' deleteflag - 1 to delete attachment file after memo sent Dim tempdir As String ' temp directory on server Dim fname As String ' filename/filepath to file to attach Dim mDoc As NotesDocument ' memo doc Dim mBody As NotesRichTextItem ' Body field of mDoc ' get file full path tempdir = Environ("Temp") fname = tempdir & "\" & expfilename ' create memo Set mDoc = db.CreateDocument() mDoc.Form = "Memo" mDoc.SaveMessageOnSend = False ' alternate from/reply field sets below 'mDoc.From = fromnm 'mDoc.Principal = fromnm 'mDoc.INetFrom = fromnm mDoc.From = db.Server mDoc.Principal = db.Server mDoc.INetFrom = db.Server mDoc.ReplyTo = fromnm mDoc.Subject = subjectnm Call mDoc.ReplaceItemValue("SendTo", sendtonms) Set mBody = mDoc.CreateRichTextItem("Body") Call mBody.AppendText("Report requested: ") Call mBody.AddNewline(2) Call mBody.EmbedObject(EMBED_ATTACHMENT, "", fname) Call mDoc.Send(False) ' remove attachment file from temporary directory If (deleteflag=1) Then ' kill any existing temp file Kill fname End If ' return success as file handle SendXLSFile = 1 End Function Function ReplaceChar(origstring As String, subchar As String, newchar As String) As String ' takes an original string (origstring) and replaces all characters of subchar with newchar ' returns the modifed (if subchar was found) string back ' this is modification of the old one stored in the mindwatering support db in that this one supports multiple characters for subchar Dim szReturn As String ' the modified string to return Dim modstring As String ' inprogress modstring Dim index As Integer ' working variable showing where subchar is or is not in the origstring Dim sublen As Integer ' # of characters length of subchar modstring = origstring sublen = Len(subchar) index = Instr(1, modstring, subchar) If sublen = 0 Then ' we have a nothing subchar so lets just return the original string ReplaceChar = origstring Exit Function End If If (index = 0) Then ' subchar was not found in origstring so we can return the original string ReplaceChar = origstring Exit Function End If While index <> 0 szReturn = Left$(modstring, index - 1) szReturn = szReturn + newchar + Mid$(modstring, index + sublen) modstring = szReturn index% = Instr(1, modstring, subchar) Wend ReplaceChar = szReturn End Function Function KillExistingFile(filepathnm As String) As Integer ' kills any existing file at location, needed to ensure new report not merged with an old report On Error Goto FErrorHandler Kill filepathnm KillExistingFile =1 GotoExit: Exit Function FErrorHandler: KillExistingFile =0 Resume GotoExit End Function