Error Checking in Excel
Thanks Thanks:  0
Likes Likes:  0
Page 2 of 2 FirstFirst 12
Results 11 to 15 of 15

Thread: VIsual basic code

  1. #11
    BatCoder
    Join Date
    Feb 2002
    Location
    Turkey
    Posts
    813
    Post Thanks / Like
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)

    Default

    Arash_The_A_Level_Student,

    Do you want to check 250th save in the same session or 250th save of the workbook?

    Oz

  2. #12
    MrExcel MVP Mark O'Brien's Avatar
    Join Date
    Feb 2002
    Location
    Columbus, OH, USA
    Posts
    3,530
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Default

    On 2002-03-07 12:48, Arash_The_A_Level_Student wrote:
    Sub Exit_Save()
    '
    ' Exit_Save Macro
    ' Exits And Saves The Excel Workbook
    Dim Wkbk As Workbook
    Dim i As Integer

    'Turn off alerts if you don't care about overwriting workbooks with the same names
    Application.DisplayAlerts = False
    For Each Wkbk In Workbooks
    If Not Wkbk Is ThisWorkbook Then
    Wkbk.Save
    Wkbk.Close
    i = i + 1
    If i = 2 Then
    MsgBox "You have Saved Your Invoice 250 Times, It's Time To Save Your Invoice Onto Removeable Media"
    End If
    End If
    Next
    End Sub

    '

    This is the code I have entered on the VB editor but it doesn't work could you please give more assistance, thanks
    Why are you putting the msgbox up when i = 2? I thought you wanted it after 250 times.


    I misread your original post, I thought you wanted to save and close 250 workbooks.

    From the message you're throwing up to the user, I can't see the point of hard coding the save and close parts at all. It seems that you just want to keep a track of how many times the user saves and/or closes a workbook.

    This is pretty simple to do. All you need to do is put a counter in a cell that isn't used and increment this by one every time the user saves the workbook. You can put this in the workbook close event. Once this value hits 250 then you can throw up your message. I've done the thinking for you, you do the code. Is learning to program part of this A Level?


    _________________
    [b] Mark O'Brien

    [ This Message was edited by: Mark O'Brien on 2002-03-07 13:42 ]

    [ This Message was edited by: Mark O'Brien on 2002-03-07 13:45 ]

  3. #13
    Board Regular
    Join Date
    Feb 2002
    Posts
    64
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Default

    well if its ict then yes/no - u can use some vba but they dont encourage out and out programming. A level computing does require it.

  4. #14
    BatCoder
    Join Date
    Feb 2002
    Location
    Turkey
    Posts
    813
    Post Thanks / Like
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)

    Default

    I think you can increase a value which you store in a builtindocumentproperty when user save it (BeforeSave event in ThisDocument module). Code like this...

    Private Sub Workbook_BeforeSave(ByVal SaveAsUI As Boolean, Cancel As Boolean)
    On Error Resume Next
    ThisWorkbook.BuiltinDocumentProperties(13) = ThisWorkbook.BuiltinDocumentProperties(13) + 1
    'Checking if property set before or not
    If Err Then ThisWorkbook.BuiltinDocumentProperties(13) = 1
    If ThisWorkbook.BuiltinDocumentProperties(13) = 250 Then
    MsgBox "You have Saved Your Invoice 250 Times, It's Time To Save Your Invoice Onto Removeable Media" & vbCrLf & "Counter will be reset.", vbInformation + vbOKOnly, "Warning!"
    ThisWorkbook.BuiltinDocumentProperties(13) = 0
    End If
    End Sub

    Just an idea...
    Oz

  5. #15
    New Member
    Join Date
    Feb 2002
    Posts
    38
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Default

    No we don't have to learn the language on the A level but my IT teacher doesn't know much and my text book has no reference on how to do this so I have to use this thing

Some videos you may like

User Tag List

Like this thread? Share it with others

Like this thread? Share it with others

Posting Permissions

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