I would like to continue use the mypath and my filename variables my goal is to have a macro that will save the ods copy and then export the pdf copy at the same time
here is my working code for save as ods in path c:\ods pdf with file name set by cell u2
- Code: Select all Expand viewCollapse view
Sub SaveAs1
On Error GoTo UNKNOWNERROR
'if fnWhichComponent(thisComponent) <> "Spreadsheet" then
exit sub
end if
Dim check as string
dim document as object
dim dispatcher as object
Dim MyFilename as string
dim MyPath as string
Dim url as string
document = ThisComponent.CurrentController.Frame
ThisComponent.currentController.setActiveSheet(ThisComponent.Sheets.getByIndex(0))
oDoc = ThisComponent
oView = oDoc.getCurrentController()
oSheet= oView.getActiveSheet().getCellRangeByName("ZZ2")
oCell = oSheet.getCellByPosition(0,0)
CHECK = oCell.getstring
If check = 5615 then
oSheet= oView.getActiveSheet().getCellRangeByName("U2")
oCell = oSheet.getCellByPosition(0,0)
MyFilename = oCell.getstring
IF MyFilename = " " then
ret& = Msgbox ("Infromation is missing, you will be prompted to save!" , 10 + 1, "INFORMATION MISSING")
EXIT SUB
end if
oSheet= oView.getActiveSheet().getCellRangeByName("U4")
oCell = oSheet.getCellByPosition(0,0)
MyPath = "C:\ods PDF\"
ret& = Msgbox ("File will be saved to folder " & MyPath & " with a filename of " & MyFilename & ".ods" , 10 + 1, "Information")
url = ConvertToUrl(MyPath & MyFilename & ".ods")
oDoc.StoreAsUrl(url,Array())
end if
EXIT SUB
UNKNOWNERROR:
ret& = Msgbox ("Unknown error, Auto save macro is disabled, and you will be prompted to save", 10 + 1, "ERROR")
End Sub