Erik Renberg wrote:

Hello,

I've been looking around for any means to use data in a spreadsheet cell to generate a filename when macro-saving.
Something like this:

FileName = "File:///C:/Documents%20&%20Settings/User/My%20Documents/File" + Sheet1.$D$4 + ".ods"

But that's of course a no go.


Any help would be convenient!

Best regards!

Erik

First question: Where do you want to save the document? Run this little macro:

 Dim  oPathSettings
 REM First, you want to determine where to store the document.
 oPathSettings = CreateUnoService("com.sun.star.util.PathSettings")
 Print oPathSettings.Work

 REM Or, do you want to store in some other location?
 Print ConvertToURL("C:\Documents & Settings\user\My Documents")


Next, you can do something like this:

Sub SaveCalcFromD4
 Dim sFileName As String
 Dim sFileHead As String
 Dim oSheet
 Dim oCell
 Dim  oPathSettings

 REM First, you want to determine where to store the document.
 oPathSettings = CreateUnoService("com.sun.star.util.PathSettings")
 sFileHead = oPathSettings.Work
 'sFileHead = ConvertToURL("C:\Documents & Settings\user\My Documents")

 oSheet = ThisComponent.getSheets().getByName("Sheet1")
 REM That is (Column, Row) and the values are zero based.
 oCell = oSheet.getCellByPosition(3, 3)

 sFileName = sFileHead & "/File" & oCell.getString() & ".ods"
 Print "Saving to " & sFileName

 REM Now, use StoreToURL or StoreAsURL as appropriate
 REM (be certain to use the correct one for your purposes).
End Sub

Hope this helps!


--
Andrew Pitonyak
My Macro Document: http://www.pitonyak.org/AndrewMacro.odt
My Book: http://www.hentzenwerke.com/catalog/oome.htm
Info:  http://www.pitonyak.org/oo.php
See Also: http://documentation.openoffice.org/HOW_TO/index.html

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to