Export table as file attachment without saving to a drive?

catbeasy

Registered User.
Local time
Today, 07:16
Joined
Feb 11, 2009
Messages
140
I am using some code that allows me to send via email an excel attachment. The excel file is created using the transferspreadsheet method and is created from a table.

What I want to know is, is it possible to save the table as an excel file but as a variable only (so the file is saved in memory only, not on a drive) and then refer to that variable in the file attachment argument of the code that sends that email? In other words, if possible, I want to skip the export step of saving the table as an excel sheet to a drive.

the function send_email_pr() is where the arguments are processed. So, at the "sendmail =" line the fileatt variable would not refer to a specific drive/file location (as it shows in the variable assignment test below), but a file only in memory. can this be done?

Thanks for any assistance..


Here is the code:

'Public Sub SendNotesMail(Subject as string, attachment as string,
'recipient as string, bodytext as string,saveit as Boolean)
'This public sub will send a mail and attachment if neccessary to the
'recipient including the body text.
'Requires that notes client is installed on the system.
Public Function sendemail_pro_pr(Subject As String, Attachment As String, Recipient As Variant, BodyText As String, SaveIt As Boolean)
'Set up the objects required for Automation into lotus notes
Dim Maildb As Object 'The mail database
Dim UserName As String 'The current users notes name
Dim MailDbName As String 'THe current users notes mail database name
Dim MailDoc As Object 'The mail document itself
Dim AttachME As Object 'The attachment richtextfile object
Dim Session As Object 'The notes session
Dim EmbedObj As Object 'The embedded object (Attachment)

Dim recip(25) As Variant
recip(25) = Forms!frm_pr_proc_sel_req.str_req_email 'need to add the text box reference here..
'Start a session to notes
Set Session = CreateObject("Notes.NotesSession")
'Next line only works with 5.x and above. Replace password with your password
'Get the sessions username and then calculate the mail file name
'You may or may not need this as for MailDBname with some systems you
'can pass an empty string or using above password you can use other mailboxes.
UserName = Session.UserName
'MailDbName = Forms!frm_MAAPS_Input_SE.mailfilename

'MailDbName = Forms!frm_MAAPS_Input!cbo_Mail_File_Name '- Add back in

'Open the mail database in notes
Set Maildb = Session.GETDATABASE("", "")
If Maildb.ISOPEN = True Then
'Already open for mail
Else
Maildb.OPENMAIL
End If
'Set up the new mail document
Set MailDoc = Maildb.CREATEDOCUMENT
MailDoc.Form = "Memo"
MailDoc.sendto = recip
MailDoc.Subject = Subject
MailDoc.Body = BodyText
MailDoc.SAVEMESSAGEONSEND = SaveIt
'Set up the embedded object and attachment and attach it
If Attachment <> "" Then
Set AttachME = MailDoc.CREATERICHTEXTITEM("Attachment")
Set EmbedObj = AttachME.EMBEDOBJECT(1454, "", Attachment, "Attachment")
' MailDoc.CREATERICHTEXTITEM ("Attachment")
End If
'Send the document
MailDoc.PostedDate = Now() 'Gets the mail to appear in the sent items folder
MailDoc.Send 0, Recipient
'Clean Up
Set Maildb = Nothing
Set MailDoc = Nothing
Set AttachME = Nothing
Set Session = Nothing
Set EmbedObj = Nothing
End Function


Public Function send_email_pr()
'2/25/09 note: this works, need to figure out if I can turn the transferspreadsheet command into a variable and use that directly as an attachment
'as opposed to saving the file to a drive first..
'also, if the above doesn't work, need to look at creating a user local folder (on C? or G?) and dropping the file there, then attaching it, sending it, then
'deleting the folder and file..
Dim sendmail As Variant
Dim recip(2) As Variant
Dim msg_pr_subj As String
Dim msg_pr_body As String
Dim fileatt As String

msg_pr_subj = "MAAPS Mark II Test"
msg_pr_body = "MAAPS Mark II Generated Email"
fileatt = "c:\readme.txt"
sendmail = sendemail_pro_pr(msg_pr_subj, fileatt, recip, msg_pr_body, True)
End Function
 
In that case, you will not be able to avoid the separate step of saving the file before attaching it. You can save the file as a temp file, attach the temp file to the Email, send the Email, then delete the temp file.
 

Users who are viewing this thread

Back
Top Bottom