I know there is a lot to my code each section does something for my needs
I found an error with the pdf label in this code and it has been corrected
Code: Select all
function fnWhichComponent(oDoc) as string
'rem function to tell oo what type of document is opened
if HasUnoInterfaces(oDoc, "com.sun.star.lang.XServiceInfo") then
if thisComponent.supportsService ("com.sun.star.text.GenericTextDocument") then
fnWhichComponent = "Text"
elseif thisComponent.supportsService("com.sun.star.sheet.SpreadsheetDocument") then
fnWhichComponent = "Spreadsheet"
elseif thisComponent.supportsService("com.sun.star.presentation.PresentationDocument") then
fnWhichComponent = "Presentation"
elseif thisComponent.supportsService("com.sun.star.drawing.GenericDrawingDocument") then
fnWhichComponent = "Drawing"
else
fnWhichComponent = "Oops current document something else"
end if
else
fnWhichComponent = "Not a document"
end if
End function
Sub SaveAs1
On Error GoTo UNKNOWNERROR
'--------checks doc type exits macro if not spredsheet seems pointless now that I added the exit on error
if fnWhichComponent(thisComponent) <> "Spreadsheet" then
exit sub
end if
'-----------sets up variables for code------
Dim check as string
dim document as object
dim dispatcher as object
Dim MyFilename as string
dim MyPath as string
Dim url as string
dim url1 as string
DIM PAGE AS STRING
document = ThisComponent.CurrentController.Frame
ThisComponent.currentController.setActiveSheet(ThisComponent.Sheets.getByIndex(0))
oDoc = ThisComponent
oView = oDoc.getCurrentController()
'------in cell zz1-3 I have a code listed that will changed the coding depending on the doc this is used for setting variables later-------
oSheet= oView.getActiveSheet().getCellRangeByName("ZZ2")
oCell = oSheet.getCellByPosition(0,0)
CHECK = oCell.getstring
'---- this section takes a file name from a cell that cell has a formula in it that takes 4 cells and makes the file name for me--------
If check = 5615 then
oSheet= oView.getActiveSheet().getCellRangeByName("U2")
oCell = oSheet.getCellByPosition(0,0)
MyFilename = oCell.getstring
'---- lets the user know auto save is disabled
IF MyFilename = " " then
ret& = Msgbox ("Infromation is missing, you will be prompted to save!" , 10 + 1, "INFORMATION MISSING")
EXIT SUB
end if
'----- sets the save as path based off a cell or you can set it manually
oSheet= oView.getActiveSheet().getCellRangeByName("U4")
oCell = oSheet.getCellByPosition(0,0)
MyPath = oCell.getstring
'------converts the file name and path to a format that basic can use
url = ConvertToUrl(MyPath & MyFilename & ".ods")
url1= ConvertToUrl(MyPath & MyFilename & ".pdf")
'dispatcher = createUnoService("com.sun.star.frame.DispatchHelper")
'ThisComponent.Sheets.getByIndex(0).unprotect("")
'-----message that informs user
ret& = Msgbox ("Files saved to folder " & MyPath & " with a filenames of " & MyFilename & " .ods and " & MyFilename & " .pdf", 10 + 1, "Information")
'---------saves the doc in ods format using the url format of filename and path
oDoc.StoreAsUrl(url,Array())
'--------sets variables for pdf export
dim args12(1) as new com.sun.star.beans.PropertyValue
dim Arg(0) as new com.sun.star.beans.PropertyValue
Doc = ThisComponent
'---- code to set pdf by range , I do by page and have set up print ranges on each sheet
'Controller = Doc.CurrentController
'Sheet = Doc.Sheets.getByName("estimate sheet1")
'CellRange = Sheet.getCellRangeByName("$A$1:$R$48")
'Controller.select(CellRange)
'Cell = Sheet.getCellByPosition(6,10)
'Arg(0).Name = "Selection"
'Arg(0).Value = CellRange
'------ I have a page indicator on my main sheet this checks for the number of pages
ThisComponent.currentController.setActiveSheet(ThisComponent.Sheets.getByIndex(0))
oSheet= oView.getActiveSheet().getCellRangeByName("W47")
oCell = oSheet.getCellByPosition(0,0)
page = oCell.getstring
'------sets the number of pages to export to pdf
IF PAGE = 1 THEN
'----sets pagerange for pdf export
Arg(0).Name = "PageRange"
'----page value for export
Arg(0).Value = "1"
args12(1).Name = "FilterData"
args12(1).Value = Arg()
goto pdf
END IF
IF PAGE = 2 THEN
Arg(0).Name = "PageRange"
Arg(0).Value = "1,2"
args12(1).Name = "FilterData"
args12(1).Value = Arg()
goto pdf
END IF
IF PAGE = 3 THEN
Arg(0).Name = "PageRange"
Arg(0).Value = "1,2,3"
args12(1).Name = "FilterData"
args12(1).Value = Arg()
goto pdf
END IF
IF PAGE = 4 THEN
Arg(0).Name = "PageRange"
Arg(0).Value = "1,2,3,4"
args12(1).Name = "FilterData"
args12(1).Value = Arg()
goto pdf
END IF
IF PAGE = 5 THEN
Arg(0).Name = "PageRange"
Arg(0).Value = "1,2,3,4,5"
args12(1).Name = "FilterData"
args12(1).Value = Arg()
goto pdf
END IF
IF PAGE = 6 THEN
Arg(0).Name = "PageRange"
Arg(0).Value = "1,2,3,4,5,6"
args12(1).Name = "FilterData"
args12(1).Value = Arg()
goto pdf
END IF
pdf:
'----sets up the pdf export
args12(0).Name = "FilterName"
args12(0).Value = "calc_pdf_Export"
'----adds the varables for pagerange or any other variables you have added
'args12(1).Name = "FilterData"
'args12(1).Value = Arg()
'-------------saves the pdf format of doc
Doc.storeToURL(url1,args12())
end if
EXIT SUB
'----- changes the standard error message to a custom one so that the code isn't exposed to the user on errors
UNKNOWNERROR:
ret& = Msgbox ("Unknown error, Auto save macro is disabled, and you will be prompted to save", 10 + 1, "ERROR")
End Sub