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

File name

 
Post new topic   Reply to topic    OOoForum.org Forum Index -> OpenOffice.org Macros and API
View previous topic :: View next topic  
Author Message
Gonzalo
Power User
Power User


Joined: 13 Apr 2004
Posts: 56

PostPosted: Fri Jul 09, 2004 2:18 am    Post subject: File name Reply with quote

Hi. I would like to save a document from a Macro, but first i need to know if there another document with that name. Is there any way to know that?

For example, if the document has no name, i need save it under the name Noname1.doc. Then, if i have to save another document with no name, i have to save it under the name Nomane2.doc. Is there any way to know that Noname1.doc exists?

Thanks.
Back to top
View user's profile Send private message
verflixtnix
Power User
Power User


Joined: 11 May 2004
Posts: 79
Location: Germany, Hamburg

PostPosted: Fri Jul 09, 2004 2:47 am    Post subject: Reply with quote

There is...
I copied it from the integrated OOo online help:
Code:

sub ExampleFileExists
msgbox FileExists("C:\autoexec.bat")
msgbox FileExists("file:///d|/bookmark.htm")
msgbox FileExists("file:///d|/privat")
end sub

or .... a few posts down with (com.sun.star.ucb.SimpleFileAccess):
http://www.oooforum.org/forum/viewtopic.php?t=10560
_________________
Jan Lüdtke

SuseLinux9.0 - OOo1.1.2 / Win2000 - OOo1.1.2
Back to top
View user's profile Send private message
JohnV
Administrator
Administrator


Joined: 07 Mar 2003
Posts: 9183
Location: Lexinton, Kentucky, USA

PostPosted: Fri Jul 09, 2004 4:52 am    Post subject: Reply with quote

Although written to force a backup of an existing file so running my macro doesn't destroy someones hard work, you may find the FileSaver subroutine found here of some benefit. Among other things it checks for an existing file.
http://www.oooforum.org/forum/viewtopic.php?t=6429
Back to top
View user's profile Send private message
flex
OOo Enthusiast
OOo Enthusiast


Joined: 06 Jul 2004
Posts: 122
Location: Vienna | Austria

PostPosted: Fri Jul 09, 2004 4:59 am    Post subject: Reply with quote

I think this i a good piece of code for saving files. Perhaps you use it.

Code:

If (Doc.isModified) Then
  If (Doc.hasLocation And (Not Doc.isReadOnly)) Then
    Doc.store()
  Else
    Doc.storeAsURL(URL, Dummy())
  End If
End If


For checking if the file is available yet, I wrote my own function. You are welcome to use it.

Code:

Function prooffile(CurrentFilePath As String) As Boolean
On Error Goto err_prooffile
'''''''''''''''''''''''''''''''''''''''''''''''''
'Erstellungsdatum:   07.07.2004               '
'Letzte Aenderung:   08.07.2004               '
'''''''''''''''''''''''''''''''''''''''''''''''''

   Dim oSimpleFileAccess as Object            'Objektvariable fuer Dateizugriff
   Dim sUrl as String                     'Variable um URL-formatierten Pfad zu speichern

   oSimpleFileAccess = createUnoService("com.sun.star.ucb.SimpleFileAccess")   'Dateizugriff initialisieren
   sUrl = ConvertToUrl(CurrentFilePath)      'aktuellen Pfad in URL-formatierten Pfad konvertieren

   prooffile =  oSimpleFileAccess.exists(sUrl)   'Existiert die Datei schon, gibt die Funktion true zurueck
                                    'andernfalls gibt sie false zurueck
exit_prooffile:
   Exit Function

err_prooffile:
   MsgBox "Error " & Err & ": " & Error$ & " (line : " & Erl & ")"
   On Error Goto 0
   Goto exit_prooffile

End Function


see also http://www.oooforum.org/forum/viewtopic.php?t=10560&highlight=
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 Macros and API 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