if link exists then ... or

mcfadwmc

Board Regular
Joined
May 10, 2005
Messages
162
what i want to do is set up a file with links to other files but if the file to link to doesn't exist then get data from somewhere in this file
for example

if a file called C:checker\mon 05.12.05 exists then get data within Mon 05.12.05 from sheet1!B3

if it doesn't exist then get data from sheet3!b3 in this file

hope this explains what i want to do

thanks in advance
 

Some videos you may like

Excel Facts

Excel Joke
Why can't spreadsheets drive cars? They crash too often!

BrianB

Well-known Member
Joined
Feb 17, 2003
Messages
8,127
This is the basic code :-
Code:
Sub test()
    Dim MyLink As String
    Dim BookLinks As Variant
    Dim MyLinkExists As Boolean
    '-----------------------------------
    MyLink = "C:\checker\mon 05.12.05"
    MyLinkExists = False
    BookLinks = ActiveWorkbook.LinkSources
    '--------------------------------------
    '- check links
    If Not IsEmpty(BookLinks) Then
        For i = 1 To UBound(BookLinks)
            If BookLinks(i) = MyLink Then
                MyLinkExists = True
            End If
        Next i
    End If
    '-------------------------------------
    If MyLinkExists = True Then
        ' do something
    Else
        ' do something else
    End If
End Sub
 

Watch MrExcel Video

Forum statistics

Threads
1,119,137
Messages
5,576,300
Members
412,716
Latest member
thviid
Top