+ Reply to Thread
Results 1 to 2 of 2

.Save / Not Working

  1. #1
    Registered User
    Join Date
    09-29-2004
    Posts
    3

    .Save / Not Working

    Anyone able to suggest why the following code does not result in an updated copy of the workbook being saved. The entries in cells A1 and A2 are not present when the file is re-opened.


    Sub SaveAndClose()

    Dim wbThis As Workbook

    Set wbThis = ActiveWorkbook
    OK = False
    On Error GoTo NotAbleToSave
    With wbThis
    Application.StatusBar = "Saving . . . "
    .Save
    Cells(1, 1) = wbThis.Name
    Cells(2, 1) = wbThis.Saved
    OK = True
    End With


    NotAbleToSave:
    Application.StatusBar = False
    If Not OK Then
    MsgBox "Backup Copy Not Saved!", vbExclamation, ThisWorkbook.Name
    End If

    wbThis.Saved = True
    Application.Quit
    End Sub


    Thanks
    Duncan

  2. #2
    Forum Contributor Kieran's Avatar
    Join Date
    10-02-2003
    Location
    Perth, Western Australia
    MS-Off Ver
    Office 2003
    Posts
    109
    Duncan,

    ita appears taht the values are set after the save, not before.
    try this small amendment

    Sub SaveAndClose()

    Dim wbThis As Workbook

    Set wbThis = ActiveWorkbook
    OK = False
    On Error GoTo NotAbleToSave
    With wbThis
    .Activesheet.Cells(1, 1).value = wbThis.Name
    .ActiveSheet.Cells(2, 1).value = wbThis.Saved
    ' note the reference to activesheet is used to indicate the correct sheet to set the values for, substitute with
    ' anything appropriate for your situation eg Sheets(2) or Sheets("data") etc
    Application.StatusBar = "Saving . . . "
    .Save
    OK = True ' OK is not defined at the satrt of the macro, I do not know if this will have any effect.
    End With


    NotAbleToSave:
    Application.StatusBar = False
    If Not OK Then
    MsgBox "Backup Copy Not Saved!", vbExclamation, ThisWorkbook.Name
    End If

    wbThis.Saved = True
    Application.Quit
    End Sub
    Kieran

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

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

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1