Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. Visual Basic
  4. Error trapping

Error trapping

Scheduled Pinned Locked Moved Visual Basic
helpquestioncareer
3 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • L Offline
    L Offline
    Lost User
    wrote on last edited by
    #1

    I wonder if anyone can help me? I have a small piece of vba in excel that works fine except for one thing. It saves a spreadsheet in as particular directory with a specified name but if it encounters a file of the same name already there and you click no to the save it then dies with error 1004. Can anyone assist? Here is the code: Private Sub CommandButton3_Click() siv = ActiveSheet.Cells(6, 2).Value 'ActiveWorkbook.SaveAs Filename:="C:\My Documents\" & siv & ".xls", FileFormat:=xlNormal, Password:="", WriteResPassword:="", ReadOnlyRecommended:=False, CreateBackup:=False On Error Resume Next ActiveWorkbook.Close End Sub X|

    N 1 Reply Last reply
    0
    • L Lost User

      I wonder if anyone can help me? I have a small piece of vba in excel that works fine except for one thing. It saves a spreadsheet in as particular directory with a specified name but if it encounters a file of the same name already there and you click no to the save it then dies with error 1004. Can anyone assist? Here is the code: Private Sub CommandButton3_Click() siv = ActiveSheet.Cells(6, 2).Value 'ActiveWorkbook.SaveAs Filename:="C:\My Documents\" & siv & ".xls", FileFormat:=xlNormal, Password:="", WriteResPassword:="", ReadOnlyRecommended:=False, CreateBackup:=False On Error Resume Next ActiveWorkbook.Close End Sub X|

      N Offline
      N Offline
      NormDroid
      wrote on last edited by
      #2

      What on earth is error 1004 is a window error code? 1004 = Invalid flags. as an internal Windows error code try using the default params?

      L 1 Reply Last reply
      0
      • N NormDroid

        What on earth is error 1004 is a window error code? 1004 = Invalid flags. as an internal Windows error code try using the default params?

        L Offline
        L Offline
        Lost User
        wrote on last edited by
        #3

        The on error resume should avoid but doesnt. The error is that it is finsindg an existing file of the same name and then falls over when you click no or cancel as oppsed to yes because the function is saveas hence the saveas has failed. SO how to get around the failure of the function????

        1 Reply Last reply
        0
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • World
        • Users
        • Groups