With File3.xls open, I'd like to run a macro that checks if File1.xls
and File2.xls are open. If either or both are not open, then open
them. The code below evaluates only the first file (File1.xls), and
never proceeds to the next step (i.e., it never checks for File2.xls).
Any idea what I need to change?

Public Sub CheckSourceDocs()

    If Not WorkbookOpen("File1.xls") Then
        Workbooks.Open Filename:="C:\File1.xls"
    ElseIf Not WorkbookOpen("File2.xls") Then
        Workbooks.Open Filename:="C:\File2.xls"
    End If

End Sub

Function WorkbookOpen(WorkBookName As String) As Boolean
    ' returns TRUE if the workbook is open
    WorkbookOpen = False
    On Error GoTo WorkBookNotOpen
    If Len(Application.Workbooks(File1.xls).Name) > 0 Then
        WorkbookOpen = True
    ElseIf Len(Application.Workbooks(File2.xls).Name) > 0 Then
        WorkbookOpen = True
        Exit Function
    End If
WorkBookNotOpen:
End Function

On a related note, File1 and File2 provide source data for File3
(i.e., they are linked, as in Edit > Links ...). The only reason I
need to open them is that this is the only way I can populate File3
with the source data. If there's a way to populate File3 without even
opening File1 and 2, I'm all ears.

-- 
----------------------------------------------------------------------------------
Some important links for excel users:
1. Follow us on TWITTER for tips tricks and links : 
http://twitter.com/exceldailytip
2. Join our LinkedIN group @ http://www.linkedin.com/groups?gid=1871310
3. Excel tutorials at http://www.excel-macros.blogspot.com
4. Learn VBA Macros at http://www.quickvba.blogspot.com
5. Excel Tips and Tricks at http://exceldailytip.blogspot.com
 
To post to this group, send email to excel-macros@googlegroups.com

<><><><><><><><><><><><><><><><><><><><><><>
Like our page on facebook , Just follow below link
http://www.facebook.com/pages/discussexcelcom/160307843985936?v=wall&ref=ts

Reply via email to