Results 1 to 3 of 3

Thread: [RESOLVED] Code to Check if Workbook Exists

Threaded View

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Nov 2010
    Posts
    272

    Resolved [RESOLVED] Code to Check if Workbook Exists

    I have (in Excel) code similar to this:
    Code:
    Public Sub One()
    Dim varStar
    Dim varStars
    
    varStar = Array("Rain", "Sleet", "Snow")
    
    For each varStar in varStars
    
    Call Precipitation (varStar)
    Call Monthly (varStar)
    Call Weekly (varStar)
    Call Yearly (varStar)
    
    Next varStar
    End Sub
    
    Public Sub Monthly (varStar)
            On Error Resume Next
            Set WB = Workbooks.Open(Filename:="" & varStar)
            Run "RefreshOnOpen"
            With WB
                WB.SaveAs Filename:="" 
            End With
            WB.Close
            On Error GoTo 0
    End Sub
    And then from there it will call the corresponding module and pass varStar to each module and run the code. The issue I have is that sometimes (like right now) it is a new year, or a new month and varStar may not exist in the specific workbook. How can I code it to, if varStar doesn't exist just skip it and keep going. I tried On Error Resume Next, and On Error GoTo 0. But that wasn't 100% efficient. If you need to see additional coding, let me know, and I can provide more.
    Last edited by Jo15765; Jan 15th, 2012 at 11:45 AM. Reason: Forgot Code Tags

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