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

What is the fastest way to copy a formula?
If A2:A50000 contain data. Enter a formula in B2. Select B2. Double-click the Fill Handle and Excel will shoot the formula down to B50000.
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,221,310
Messages
6,159,176
Members
451,543
Latest member
cesymcox

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