Consulting

Results 1 to 9 of 9

Thread: Solved: Email code crashes if workbook isn't saved

  1. #1
    VBAX Master
    Joined
    Jun 2006
    Posts
    1,091
    Location

    Solved: Email code crashes if workbook isn't saved

    I use some email code and it works perfectly 98% of the time. However, if the workbook hasn't been saved yet it crashes. So, I decided to test this code:

    VBA:
    If ThisWorkbook.Saved = False Then Error00_01_04.Show End If
    VBA tags courtesy of www.thecodenet.com

    and Error00_01_04 shows up all the time. Even if the workbook has been saved before?

  2. #2
    Moderator VBAX Wizard lucas's Avatar
    Joined
    Jun 2004
    Location
    Tulsa, Oklahoma
    Posts
    7,323
    Location
    Why not just save it with the code..?
    Steve
    "Nearly all men can stand adversity, but if you want to test a man's character, give him power."
    -Abraham Lincoln

  3. #3
    VBAX Master
    Joined
    Jun 2006
    Posts
    1,091
    Location
    Because if the user has never done a Save-As before.

  4. #4
    Moderator VBAX Wizard lucas's Avatar
    Joined
    Jun 2004
    Location
    Tulsa, Oklahoma
    Posts
    7,323
    Location
    [VBA]If ThisWorkbook.Saved = False Then
    MsgBox "Save this workbook before proceeding"
    End If[/VBA]

    Daniel I can't believe you were actually able to even run the code you posted in post#1......
    Steve
    "Nearly all men can stand adversity, but if you want to test a man's character, give him power."
    -Abraham Lincoln

  5. #5
    VBAX Master
    Joined
    Jun 2006
    Posts
    1,091
    Location
    Lucas,

    it wasn't on one line, when I copied it over I didn't relieze it messed up like that. It is supposed to be:

    [VBA]Sub Error00_01_04code()
    If ThisWorkbook.Saved = False Then
    Error00_01_04.Show
    End If

    End Sub[/VBA]

    Unfortunately, it always shows up even if it has been saved.

  6. #6
    Moderator VBAX Guru Simon Lloyd's Avatar
    Joined
    Sep 2005
    Location
    UK
    Posts
    3,003
    Location
    [VBA]Sub Error00_01_04code()
    If ThisWorkbook.Saved <> False Then

    Else: Error00_01_04.Show
    End If

    End Sub[/VBA]this worked for me, unsaved and i got the UF saved i got nothing!

    Regards,
    Simon
    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)

  7. #7
    VBAX Master
    Joined
    Jun 2006
    Posts
    1,091
    Location
    Activeworkbook.saved works for me

    I guess by using Thisworkbook it was looking at the add-in workbook

  8. #8
    Moderator VBAX Guru Simon Lloyd's Avatar
    Joined
    Sep 2005
    Location
    UK
    Posts
    3,003
    Location
    Its quite possible, glad its solved for you!

    Regards,
    Simon
    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)

  9. #9
    Moderator VBAX Wizard lucas's Avatar
    Joined
    Jun 2004
    Location
    Tulsa, Oklahoma
    Posts
    7,323
    Location
    always use activeworkbook in your addins as thisworkbook will refer to the addin....
    Steve
    "Nearly all men can stand adversity, but if you want to test a man's character, give him power."
    -Abraham Lincoln

Posting Permissions

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