|
-
Jan 15th, 2012, 11:41 AM
#1
Thread Starter
Hyperactive Member
[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
-
Jan 15th, 2012, 12:36 PM
#2
Re: Code to Check if Workbook Exists
Greetings, this forum is for VB.NET issues which include Office automation but not for VBA issues. The correct forum is here http://www.vbforums.com/forumdisplay.php?f=37
-
Jan 15th, 2012, 12:40 PM
#3
Thread Starter
Hyperactive Member
Re: Code to Check if Workbook Exists
Oh, thanks for the info! I re posted my question there!
here to be exact
http://www.vbforums.com/showthread.p...57#post4118557
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|