[Solved] Custom "Save as" in Macro?

Discuss the spreadsheet application
Post Reply
estevemartin
Posts: 5
Joined: Wed Jul 08, 2009 1:54 pm

[Solved] Custom "Save as" in Macro?

Post by estevemartin »

I have recorded this macro with the following being at the end. I would like to replace the "REPLACE" portion with a cell that I also have updating during the macro. Every time I run the macro cell B4 goes from "week 1" to "week 2" to "week 3"..... and I would like to file name to do the same after running the macro.

Also, is there a way to combine two macros? Or how do I add to a macro?

Code: Select all

rem ----------------------------------------------------------------------
dim args7(1) as new com.sun.star.beans.PropertyValue
args7(0).Name = "URL"
args7(0).Value = "file:///C:/Documents%20and%20Settings/Steve_Martin/My%20Documents/bowling_docs/[color=#FF0000]REPLACE[/color].ods"
args7(1).Name = "FilterName"
args7(1).Value = "calc8"

dispatcher.executeDispatch(document, ".uno:SaveAs", "", 0, args7())

end sub
Thanks,

Steve
Last edited by estevemartin on Tue Oct 30, 2012 3:04 pm, edited 2 times in total.
OOo 3.1.X on Ms Windows XP + windows 2000
FJCC
Moderator
Posts: 9277
Joined: Sat Nov 08, 2008 8:08 pm
Location: Colorado, USA

Re: Custom "Save as" in Macro?

Post by FJCC »

You have to add some non-recorded code to do this. If the file name is in cell D1 of a sheet named Sheet1, the code at the end of your macro would look like this.

Code: Select all

oDoc = ThisComponent
Sheets = oDoc.Sheets
Sheet = Sheets.getByName("Sheet1")  'change this to your sheet name
Cell = Sheet.getCellRangeByName("D1")  'change this to the cell that has the file name
FileName = Cell.String
FileNameWithExtension = Filename + ".ods"

DirectoryName = "file:///C:/Documents%20and%20Settings/Steve_Martin/My%20Documents/bowling_docs/"
FullFileName = DirectoryName + FileNameWithExtension

rem ----------------------------------------------------------------------
dim args7(1) as new com.sun.star.beans.PropertyValue
args7(0).Name = "URL"
args7(0).Value = FullFileName
args7(1).Name = "FilterName"
args7(1).Value = "calc8"

dispatcher.executeDispatch(document, ".uno:SaveAs", "", 0, args7())

End Sub
This just gets the file name from the cell, adds the .ods and directory information to the name and uses this constructed name as the value of args7(0).Value.
OpenOffice 4.1 on Windows 10 and Linux Mint
If your question is answered, please go to your first post, select the Edit button, and add [Solved] to the beginning of the title.
Post Reply