I have (in Excel) code similar to this:
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.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




Reply With Quote