Re: Workbook_BeforeSave()

Tech-Archive recommends: Fix windows errors by optimizing your registry

From: bmm (newsgroup.com)
Date: 08/16/04


Date: Mon, 16 Aug 2004 19:07:03 +0530

Thanks Tom,
this code works but when i try to save the file with the the existing file
name,
it asks if i want to replace the existing file, if i say No/ Cancel then it
gives me an Run time error "1004"
which says
"Method SaveAs of object '_Workbook' failed "
Can you please explain me why is it so?

Thanks once again

"Tom Ogilvy" <twogilvy@msn.com> wrote in message
news:OR9NDG5gEHA.1344@TK2MSFTNGP11.phx.gbl...
> Private Sub Workbook_BeforeSave(ByVal SaveAsUI As Boolean, -
> Cancel As Boolean)
> Application.EnableEvents = False
> filesavename = Application.GetSaveAsFilename( _
> fileFilter:="Microsoft Excle Files Files (*.xls), *.xls")
> If filesavename <> False Then
> Thisworkbook.SaveAs FileName:=filesavename
> End If
> Application.EnableEvents = True
> Cancel = True
> End Sub
>
> --
> Regards,
> Tom Ogilvy
>
>
> "bmm" <newsgroup.com> wrote in message
> news:uNlvuz4gEHA.216@tk2msftngp13.phx.gbl...
> > Hi,
> > How can I trap the file save as /save event and get the filename entered
> in
> > the dialogbox?
> > I tried to get the file name in "Workbook_BeforeSave() " event, but it
> > displays the dialog twice FileSave As dialog twice.
> > How can i avoid that dialog appearing twice
> >
> > Private Sub Workbook_BeforeSave(ByVal SaveAsUI As Boolean, Cancel As
> > Boolean)
> > Application.EnableEvents = False
> > filesavename = Application.GetSaveAsFilename( _
> > fileFilter:="Microsoft Excle Files Files (*.xls), *.xls")
> > If filesavename <> False Then
> > filesavename = filesavename
> > End If
> > Application.EnableEvents = True
> > Cancel = True
> > MsgBox filesavename
> > End Sub
> >
> >
> >
> >
>
>



Relevant Pages

  • Re: Placing code
    ... you have "Private Sub Form_BeforeUpdate in twice at ... Form_BeforeUpdate (Cancel As Integer)") and last lines for you. ...
    (microsoft.public.access.formscoding)
  • Workbook_BeforeSave()
    ... displays the dialog twice FileSave As dialog twice. ... Private Sub Workbook_BeforeSave(ByVal SaveAsUI As Boolean, Cancel As ...
    (microsoft.public.excel.programming)
  • Re: More efficient code for If Else data validation rule?
    ... cboFavoriteColor. ... if i'm going to cancel an event, i normally do it before taking ... Private Sub cboFavoriteColor_BeforeUpdate ...
    (microsoft.public.access.formscoding)
  • Re: More efficient code for If Else data validation rule?
    ... cboFavoriteColor = "Other" evaluates to Null, then the value of the Enabled ... if i'm going to cancel an event, i normally do it before taking ... Private Sub cboFavoriteColor_BeforeUpdate ...
    (microsoft.public.access.formscoding)
  • Re: Require input in a cell before saving file
    ... Private Sub Workbook_BeforeSave(ByVal SaveAsUI As Boolean, ... Cancel As Boolean) ... Gord Dibben MS Excel MVP ...
    (microsoft.public.excel.misc)