I have found macros to save using file content like this and macros that will "Save As" but I haven't been able to combine the two. My guess is that I just need to add the Save As function with 'Filter' somewhere but I am at a loss.
I also want to pull the e-mail address from a cell also.
Any suggestions?
Code: Select all
sub print_email
oDoc =ThisComponent
oSheet = oDoc.Sheets(0)
c = oSheet.getCellRangeByName("G4").String
sPath ="C:\Documents and Settings\My Documents\Returns\"
rem if not fileexists(sPath) then
rem msgbox "Path does not exist"
rem endif
oDoc =ThisComponent
oSheet = oDoc.Sheets(0)
a = oSheet.getCellRangeByName("C1").String
b = CDatetoISO(NOW)
sFile= sPath & a & " " & Format( Now(), "YYYY"+"-"+"MM"+"-"+"DD"+"_"+"HH"+"-"+"MM"+"-"+"SS" )+".ods"
Url = ConvertToUrl(sFile)
If FileExists(Url) then
iAns = MsgBox("Click 'OK' to overwrite the existing file.",1," !!! FILE EXISTS !!!"
If iAns <> 1 then End
else
msgbox "going to save"& sFile
EndIf
oDoc.StoreAsUrl(Url,Array())
rem begin working macro
rem ----------------------------------------------------------------------
rem define variables
dim document as object
dim dispatcher as object
rem ----------------------------------------------------------------------
rem get access to the document
document = ThisComponent.CurrentController.Frame
dispatcher = createUnoService("com.sun.star.frame.DispatchHelper")
rem ----------------------------------------------------------------------
dispatcher.executeDispatch(document, ".uno:PrintDefault", "", 0, Array())
dispatcher.executeDispatch(document, ".uno:PrintDefault", "", 0, Array())
Dim aAttachement(0) As String, aCCRecipients(0) As String
sRecipient = "myemail@mycompany.com"
sSubject = "Rx Return Sheet"
aAttachement(0) = ConvertToURL(ThisComponent.URL)
nFlag = 1 '0-opens compose window, 1-sends mail immediately
Call subSendMail(sRecipient,sSubject,aAttachement(),nFlag)
End Sub
Sub subSendMail(sRecipient As String,sSubject As String,aAttachements,nFlag As Integer)
' nFlag: '0-opens compose window, 1-sends mail immediately
oMailer = createUnoService( "com.sun.star.system.SimpleSystemMail" )
oMailClient = oMailer.querySimpleMailClient()
oMessage = oMailClient.createSimpleMailMessage()
oMessage.setRecipient( sRecipient )
oMessage.setSubject( sSubject )
oMessage.setAttachement( aAttachements() )
oMailClient.sendSimpleMailMessage(oMessage,nFlag)
End Sub