Consulting

Results 1 to 3 of 3

Thread: save function not working properly

  1. #1
    VBAX Regular
    Joined
    Jul 2008
    Posts
    43
    Location

    save function not working properly

    I'm pretty new to VBA. Trying to get a file to automaticly chose a file name and save the workbook when you try to exit it. Its not finding the name or letting me exit. Can anyone tell me whats wrong with my code?




    [VBA] Private Sub Workbook_BeforeClose(Cancel As Boolean)
    On Error GoTo Exits
    Cancel = True
    Application.EnableEvents = False
    With ActiveSheet
    ActiveWorkbook.SaveCopyAs "C:\TimeSheets\" & Format(Worksheets(3).Range("A12"), " yy-mm-dd") & Worksheets(3).Range("H10") & ".xls"
    End With
    Exits:
    Application.EnableEvents = True
    End Sub[/VBA]

    Aussiebear: When adding sections of code, please use the VBA button to wrap your code. It makes the code so much easier to read.

  2. #2
    Hi,

    Try using ActiveWorkbook.SaveAs ......
    But this should be used for the first time to save.

    For subsequent saves you will have to use SAVE

    Hope this helps.

  3. #3
    See if this helps...

    [VBA]Private Sub Workbook_BeforeClose(Cancel As Boolean)
    On Error GoTo Exits
    Application.EnableEvents = False
    With ActiveWorkbook
    .SaveCopyAs "C:\TimeSheets\" & Format(.Worksheets(3).Range("A12"), "YY-MM-DD") & .Worksheets(3).Range("H10") & ".xls"
    End With
    Exits:
    Application.EnableEvents = True
    End Sub [/VBA]

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •