OpenOffice.org Forum at OOoForum.orgThe OpenOffice.org Forum
 
 [Home]   [FAQ]   [Search]   [Memberlist]   [Usergroups]   [Register
 [Profile]   [Log in to check your private messages]   [Log in

Auto Generate Save As Filename?

 
Post new topic   Reply to topic    OOoForum.org Forum Index -> OpenOffice.org Calc
View previous topic :: View next topic  
Author Message
KP4U
General User
General User


Joined: 06 Sep 2005
Posts: 29

PostPosted: Fri Mar 09, 2007 8:24 am    Post subject: Auto Generate Save As Filename? Reply with quote

Hello, I'm a shipper/receiver and I fill out all my packing slips with Calc document. Basically I open a document template, fill out the recipients name, address, date and then the products and quantities. Every time I select "Save As" I have to enter the customer name and date. I was wondering if there was a way to auto generate the filename in the Save As dialog based on 1 or 2 cells in the document, like the customer name and/or date for instance. That way I could select "Save As" and hit enter and that would be it.

Any help here much appreciated. Thanks.
Back to top
View user's profile Send private message
squenson
Super User
Super User


Joined: 09 Mar 2007
Posts: 690
Location: Nis, Serbia

PostPosted: Fri Mar 09, 2007 12:41 pm    Post subject: Reply with quote

KP4U,

I suggest that you have a cell in your spreadsheet that contains the name of the file, based on a combination of customer and date. For example, if the cell D7 contains the customer name, you could create in any empty cell a formula like:
= "C:\Path_Of_My_Files\" & D7 & TEXT(NOW();"yyyymmdd") & ".ods"

Now, just before saving your file, select this cell, press CTRL+C (or right click in the cell and copy), click on File, Save As, and press CTRL+V (or right click in the file name box and paste), then press ENTER button. This way, you do not have to retype all the characters of the name.

You could also create a macro associated with a button that does that, but it will require slightly more time to develop and test, and the additional time saving will be marginal.

Hope this help,
Stephane Quenson.
Back to top
View user's profile Send private message
Villeroy
Super User
Super User


Joined: 04 Oct 2004
Posts: 7649
Location: Germany

PostPosted: Fri Mar 09, 2007 1:06 pm    Post subject: Reply with quote

Quote:
You could also create a macro associated with a button that does that, but it will require slightly more time to develop and test, and the additional time saving will be marginal.

Well, that depends on how many ships leave the harbour today Wink
Yes, this is one way I have thought of:
= "C:\Path_Of_My_Files\" & D7 & TEXT(NOW();"yyyymmdd") & ".ods"
Create a named cell, which displays the right path-name to save as and
wrap this into a hyperlink, calling a macro:
=HYPERLINK("vnd.sun.star.script:Standard.Module1.AutoSaveByCellValue?location=document&language=Basic"; "C:\Path_Of_My_Files\" & D7 & TEXT(NOW();"yyyymmdd") & ".ods")
This shows the path-name of the file and when you click on it, the file gets saved.
Open your template for editing
Call Menu:Tools>Options>Macros>Basic...
Browse to your template's library "Standard" and hit button "New...", accept the default name "Module1" and replace the content of the module with the following code.
In the document create a named single cell "MyPath". It can be the same cell as the hyperlink-cell as long as it displays the right path-name.
You may use any other name and adapt the name on top of the macro accordingly:
const sPathCell = "MyPath"
Code:

REM  *****  BASIC  *****
Option Explicit
Sub AutoSaveByCellValue()
REM Three names of single cells in this document:
const sPathCell = "MyPath"
Dim oCell, oRange, sURL$, oNames, iOK%
   oNames = thisComponent.NamedRanges
   if oNames.hasByName(sPathCell) then
      oRange = oNames.getByName(sPathCell).getReferredCells()
      if not isNull(oRange) then
         oCell = oRange.getCellByPosition(0,0)
      endif
   else
      msgbox "No such range-name: "& sName
   endif
   if isObject(oCell) then   sURL = oCell.getString()
   if sURL = "" then
      msgbox "Could not retrieve string of named cell "& sPathCell,64,"AutoSaveByCellValue()"
      exit sub
   endif
   sURL = convertToURL(sURL)
   if FileExists(sURL) then
      iOK = MsgBox(sURL &" already exists. Overwrite?",49,"AutoSaveByCellValue()")
   else
      iOK = 1
   endif
   if iOK <> 1 then exit sub
   on error goto saveErr
   thisComponent.storeAsURL(sURL,Array())
   msgbox "Saved as "& sURL,48,"AutoSaveByCellValue()"
exit sub
saveErr:
   msgbox "Something went wrong saving "& sURL,64,"AutoSaveByCellValue()"
End Sub

_________________
XUbuntu 9.04, OOo 3.1.1(Sun), Sun Java 1.5.0_06
Back to top
View user's profile Send private message
MrBill1028
General User
General User


Joined: 13 Sep 2008
Posts: 15
Location: COLORADO

PostPosted: Sun Jan 04, 2009 8:21 am    Post subject: Reply with quote

I'm confused as to what the "MyPath " cell is supose to contain? I entered "V10" the cell that I put the hyperlink in in my document but it gets down to the statement "else" and comes back with an errror "variable not defined"? Were do you enter the Variable or what am I missing?
_________________
Rank Amateur Willing To Learn
Back to top
View user's profile Send private message
Villeroy
Super User
Super User


Joined: 04 Oct 2004
Posts: 7649
Location: Germany

PostPosted: Sat Mar 28, 2009 10:45 am    Post subject: Reply with quote

Quote:
I'm confused as to what the "MyPath " cell is supose to contain?

Select a cell and type MyPath into the name box, left of the formula bar.
Put any valid, full path-name C:\path\file.ods into this named cell and run the macro.
Put any formula expression into the cell which calculates a valid, full path-name and run the macro.
Code:
= "C:\Path_Of_My_Files\" & D7 & TEXT(NOW();"yyyymmdd") & ".ods"

... returns a valid, full path-name for Windows if C:\Path_Of_My_Files\ is an existing directory.


Code:
=HYPERLINK("vnd.sun.star.script:Standard.Module1.AutoSaveByCellValue?location=document&language=Basic"; "C:\Path_Of_My_Files\" & D7 & TEXT(NOW();"yyyymmdd") & ".ods")

... puts the same text into the named cell, including a clickable hyperlink calling the macro "AutoSaveByCellValue" stored in Standard.Module1 of this very same document.
_________________
XUbuntu 9.04, OOo 3.1.1(Sun), Sun Java 1.5.0_06
Back to top
View user's profile Send private message
MrBill1028
General User
General User


Joined: 13 Sep 2008
Posts: 15
Location: COLORADO

PostPosted: Sun Mar 29, 2009 8:33 am    Post subject: Reply with quote

John: Thank-you for your response. I finally figured out (after many months) where to create the "MyPath" named Range. I guess if I'd searched for Ooo for Naming Ranges I would have found it soon (da) You are great and I would like to THANK-YOU for all of your help. My project is now complete and is saving alot of time.
_________________
Rank Amateur Willing To Learn
Back to top
View user's profile Send private message
blindvic
General User
General User


Joined: 11 Feb 2007
Posts: 40
Location: Moldova

PostPosted: Thu Apr 16, 2009 10:53 pm    Post subject: Reply with quote

So, there is no way to set a default name for the newly created document, if i created the document by a macro and i don't want macro in the document?
Back to top
View user's profile Send private message
Villeroy
Super User
Super User


Joined: 04 Oct 2004
Posts: 7649
Location: Germany

PostPosted: Fri Apr 17, 2009 12:20 am    Post subject: Reply with quote

blindvic wrote:
So, there is no way to set a default name for the newly created document, if i created the document by a macro and i don't want macro in the document?


Intercept .uno:SaveAs for every new document.
http://wiki.services.openoffice.org/wiki/Documentation/DevGuide/OfficeDev/Dispatch_Interception
No, it's not easy. Yes, a programming language other than Basic may be required (not shure).
_________________
XUbuntu 9.04, OOo 3.1.1(Sun), Sun Java 1.5.0_06
Back to top
View user's profile Send private message
blindvic
General User
General User


Joined: 11 Feb 2007
Posts: 40
Location: Moldova

PostPosted: Tue Apr 21, 2009 1:21 am    Post subject: Reply with quote

I think we must introduce a new parameter when creating a document through a macro - "default_filename" or something like this. But i don't think it will be implemented in next several years taking into consideration how the work is going on.
Sad
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    OOoForum.org Forum Index -> OpenOffice.org Calc All times are GMT - 8 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group