Results 1 to 6 of 6

Thread: On error, resume

  1. #1

    Thread Starter
    Member
    Join Date
    Mar 2006
    Posts
    62

    On error, resume

    I have a sheet that when opened, populates it's data via vlookups and opens 4 more sheets for updating purposes.

    Currently, if I already have any of those 4 sheets open, the macro breaks. What I would like to be able to do is have the main sheet run it's macro and if it sees that the sheet it's trying to open, is already open, skip it and continue on to the next one.

    I tried the help files but came up wanting. Any help would be appreciated.

    "If at first you don't succeed, destroy all evidence you ever tried."
    http://www.ussretribution.com

  2. #2
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    Re: On error, resume

    Post your code where your attempting to open one of the sheets. Are the sheets hidden or just dont exist in the workbook at that time and get .Add'ed?
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

  3. #3

    Thread Starter
    Member
    Join Date
    Mar 2006
    Posts
    62

    Re: On error, resume

    Series of filters and other code precedes this.

    Sheets("Sheet1").Select
    Workbooks.Open Filename:= _
    "\\jca\local\80g\Sam\washrep.xls", updatelinks:=0
    Workbooks.Open Filename:= _
    "\\jca\local\80g\Sam\Database.xls", updatelinks:=0
    Workbooks.Open Filename:= _
    "\\jca\local\80g\Sam\COs.xls", updatelinks:=0
    Workbooks.Open Filename:= _
    "\\jca\local\80g\Sam\monthlyrep.xls", updatelinks:=0
    Windows("Sheet1.xls").Activate

    ~~~Bunch of other updates follow this.

    "If at first you don't succeed, destroy all evidence you ever tried."
    http://www.ussretribution.com

  4. #4
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    Re: On error, resume

    Ok, to check if your desired workbook is already open then you would iterate through the workbooks collection looking for a match.
    VB Code:
    1. Dim i As Integer
    2. Dim bFound As Boolean
    3. For i = 1 to Workbooks.Count
    4.     If Workbooks(i).Name = "\\jca\local\80g\Sam\washrep.xls" Then
    5.         MsgBox "Already Open"
    6.         bFound = True
    7.         Exit For
    8.     End If
    9. Next
    10. If bFound = False Then MsbBox "Not Opened"
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

  5. #5

    Thread Starter
    Member
    Join Date
    Mar 2006
    Posts
    62

    Re: On error, resume

    Hmmm...couldn't seem to get it to work. I'm going to play with it on a saved copy and see what I get but, if possible, are there other codes to try?

    "If at first you don't succeed, destroy all evidence you ever tried."
    http://www.ussretribution.com

  6. #6
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    Re: On error, resume

    Nope, thats about the only way other then error trapping the already open workbook error.

    What error did you get?
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

Posting Permissions

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



Click Here to Expand Forum to Full Width