Consulting

Results 1 to 2 of 2

Thread: beforeclose, saving the workbook

  1. #1

    beforeclose, saving the workbook

    hello again,

    in the Beforeclose event handler I have this:

    [vba]
    Dim Wk As Workbook
    Set Wk = Workbooks("02 Output.xls")
    If Wk.ReadOnly = False Then
    Call Save_msg
    End If
    [/vba]
    then the sub Save_msg is shows up a message box: if the user decides to save the workbook I am calling the sub: Save_wb

    [vba]

    Dim Wk As Workbook
    Set Wk = Workbooks("02 Output.xls")
    Application.DisplayAlerts = False
    Wk.SaveAs Filename:="P:/Product Monitors/Backup/02 Output.xls"
    Call Backup_msg
    [/vba]

    the thing is: even though I have R/Write privileges Excel returns an errors saying that the file is write protected... any idea why? (i can use a Ctrl + S to save though without any problem)

    any idea on what's going wrong ??

    thanks for your help!

  2. #2
    Site Admin VBAX Guru Simon Lloyd's Avatar
    Joined
    Sep 2005
    Location
    UK
    Posts
    3,005
    Location
    For a start you have the file switch set wrong!
    [VBA]
    Dim Wk As Workbook
    Set Wk = Workbooks("02 Output.xls")
    Application.DisplayAlerts = False
    Wk.SaveAs Filename:="P:/Product Monitors/Backup/02 Output.xls"
    Call Backup_msg
    [/VBA]should look like:
    [VBA]
    Dim Wk As Workbook
    Set Wk = Workbooks("02 Output.xls")
    Application.DisplayAlerts = False
    Wk.SaveAs Filename:="P:\Product Monitors\Backup\02 Output.xls"
    Call Backup_msg
    [/VBA]
    Regards,
    Simon
    Please read this before cross posting!
    In the unlikely event you didn't get your answer here try Microsoft Office Discussion @ The Code Cage
    If I have seen further it is by standing on the shoulders of giants.
    Isaac Newton, Letter to Robert Hooke, February 5, 1675 English mathematician & physicist (1642 - 1727)

Posting Permissions

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