VBA Code to prevent inclusion of external links in the Workbook

gubertu

Board Regular
Joined
May 24, 2015
Messages
148
Hi all,

I hope you can help me with this.

I need a code to prevent that any external link or reference can be included in my Workbook.

For example, I have my Workbook "Master" and someone wants to include in it a reference from another Workbook called "Country", let´s say in tab "Data", cell "A1".

If there is no protection, it will appear the following reference, in my Workbook "Master" = [Country]Data!$A$1.

Well, what I need is, when someone tries to do include some external reference, some message appears like "You cannot include external references in this Workbook" and do not allow to include anything.

Hope you can help me.

Thanks in advance!
 

Excel Facts

Lock one reference in a formula
Need 1 part of a formula to always point to the same range? use $ signs: $V$2:$Z$99 will always point to V2:Z99, even after copying
Try this

In ThisWorbook module (will not work in standard module)
Code:
Private Sub Workbook_SheetChange(ByVal Sh As Object, ByVal Target As Range)
    Call BreakExternalLinks
End Sub

Private Sub BreakExternalLinks()
[I][COLOR=#006400]'(Code is modified slightly)Original source: www.TheSpreadsheetGuru.com/The-Code-Vault[/COLOR][/I]
    Dim ExternalLinks As Variant, wb As Workbook, x As Long
    On Error Resume Next
    Set wb = ActiveWorkbook
    ExternalLinks = wb.LinkSources(Type:=xlLinkTypeExcelLinks)
    On Error GoTo Handling
    For x = 1 To UBound(ExternalLinks)
        MsgBox "You cannot include external references in this Workbook"
        wb.BreakLink Name:=ExternalLinks(x), Type:=xlLinkTypeExcelLinks
     Next x
Handling:
End Sub
 
Upvote 0

Forum statistics

Threads
1,223,164
Messages
6,170,444
Members
452,326
Latest member
johnshaji

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
Back
Top