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
 

Excel Facts

Quick Sum
Select a range of cells. The total appears in bottom right of Excel screen. Right-click total to add Max, Min, Count, Average.

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
 
Master Excel Bundle

Excel contains over 450 functions, with more added every year. That’s a huge number, so where should you start? Right here with this bundle.

Forum statistics

Threads
1,163,624
Messages
5,832,742
Members
430,160
Latest member
a_majda

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Top