-
-
Save hedgejanuary/2e8044cfc23991bcba083d95b683bd2b to your computer and use it in GitHub Desktop.
Check if the workbook has external link and remove the link where necessary.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sub RemoveExternalLink() | |
'他のエクセルファイルとのリンクがあるかを確認し、あれば、リンクの解除・非解除処理を行う。 | |
'アドインとして登録しているため、ThisWorkbookではなくActiveWorkbookとしている。 | |
Dim msg As VbMsgBoxResult '選択したメッセージの値 | |
Dim aryLink As Variant '外部リンクの格納 | |
Dim i As Long | |
aryLink = ActiveWorkbook.LinkSources(xlExcelLinks) | |
'他のブックへのリンクがあるかを確認し、リンクを削除するか選択する。 | |
If IsArray(aryLink) Then | |
msg = MsgBox("他のブックへのリンクがあります! " & vbCrLf & "リンクを解除しますか?", vbYesNo + vbQuestion) | |
If msg = vbYes Then | |
'リンクを削除する | |
For i = 1 To UBound(aryLink) | |
ActiveWorkbook.BreakLink _ | |
Name:=aryLink(i), _ | |
Type:=xlLinkTypeExcelLinks | |
Next i | |
Else | |
MsgBox "リンクを解除していません。" | |
End If | |
Else | |
MsgBox "他のブックへのリンクはありませんでした。" | |
Exit Sub | |
End If | |
MsgBox "DONE" | |
End Sub |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment