Re: What's the most efficient to check a file name is valid?

Tech-Archive recommends: Repair Windows Errors & Optimize Windows Performance



Thanks, but I have a particular reason for wanting to seperate the save
dialogue and the actual saving of the file.

I'm going to copy a sheet from one workbook to another, after stripping the
conditional formatting in each visible cell. There's a lot of calulations
involved so I want to give the user a chance to cancel before doing the
processing.

At the moment I copy the use provided file name into a string and don't use
it until the end of a long process.

- Rm


"JMB" wrote:

> What about using the SaveAs dialog box?
>
> Application.Dialogs(xlDialogSaveAs).Show
> If Not ThisWorkbook.Saved Then _
> MsgBox "Not Saved"
>
>
> "Robert Mulroney" wrote:
>
> >
> > That's just the problem I thought that the GetSaveAsFilename would check the
> > resulting string's validity but it doesn't appear to be doing it. The "Save
> > As" dialogue just spits back whatever it's given. Am I doing something wrong?
> >
> >
> >
> > Dim TargetName as String
> >
> > TargetName = Application.GetSaveAsFilename(TargetName, _
> > fileFilter:="Excel Files (*.xls), *.xls")
> >
> > .
> >
> > ' Some Other Stuff
> > .
> >
> > 'Save the file
> > Call ActiveWorkbook.SaveAs(TargetName)
> > ActiveWorkbook.Close
> >
> >
> > - Rm
> >
> >
> > "Dave Peterson" wrote:
> >
> > > Is this so you can ask the user for a name and then save it as that name?
> > >
> > > If yes, then I would think that the best thing to do would be to not test it at
> > > all. Just use application.GetSaveAsFilename and let the operating system take
> > > care of it.
> > >
> > > If you're gonna use a cell in a worksheet and want to validate that, I wouldn't
> > > bother.
> > >
> > > I'd just try saving the workbook with that name and see if there was an error.
> > >
> > > on error resume next
> > > with activesheet
> > > .parent.saveas filename:="C:\somefolder\" & .range("a1").value & ".xls", _
> > > fileformat:=xlworkbooknormal
> > > end with
> > > if err.number <> 0 then
> > > msgbox "it didn't save
> > > err.clear
> > > end if
> > > on error goto 0
> > >
> > > =====
> > > Not only are there characters that can't be used in filenames, there are some
> > > names that can't be used--the old DOS devices: LPT1, LPT2, CON, PRN and the
> > > like.
> > >
> > > ===
> > > Well, I would check to see if cell was empty first--just in case.
> > >
> > >
> > >
> > >
> > > Robert Mulroney wrote:
> > > >
> > > > What is the most efficient way for checking that a potential file name is
> > > > valid ?
> > > >
> > > > File names cannot include some charaters like * / : \ ? < > is there a
> > > > function somewhere that checks a file name and pop's up the windows "invalid
> > > > file name" dialogue?
> > > >
> > > > - Rm
> > >
> > > --
> > >
> > > Dave Peterson
> > >
.



Relevant Pages

  • Re: No smooth transition to the next form
    ... I am reading the textfile line by line. ... same string after the blank spaces. ... > I'm not sure how you're populating your combo boxes but you get the idea. ... So I am calling the same function for Saving in the ...
    (microsoft.public.dotnet.framework.compactframework)
  • Re: DBLookupComboBox question
    ... // Instead of saving the Cathegory String value from Table1, ... then it's garbage anyway. ...
    (comp.lang.pascal.delphi.misc)
  • Re: FileDialog browse button: how do you specify the default directory
    ... If not, it's just a dialogue, not a saving ... Sub GetFile ... Dim retFile As String, dlg As Variant, s As String ...
    (microsoft.public.access.formscoding)
  • Re: FileDialog browse button: how do you specify the default directory
    ... > Amy, if you can explain how to use the SaveAs option of the FileDialog, I ... rather than allenbrowne at mvps dot org. ... If not, it's just a dialogue, not a saving ... >> you use the dialogue to pick a file or folder. ...
    (microsoft.public.access.formscoding)
  • Re: rich text format
    ... If I'm saving the string to a database and displaying it using a quickrep, ...
    (alt.comp.lang.borland-delphi)