Hi All,
I am working on an Excel file which has 12 sheets in total of which the following 5 sheets only are protected and have links to another excel file. Because of links to another file, the file I am working on is huge in size (about 10 MB).
1. Quote 1
2. Quote 2
3. Quote 3
4. Quote 4
5. Quote 5
So I have written below macro to first unprotect these 5 sheets, then break the links and finally protect the sheets again.
Sub BreakThoseLinks()
Application.ScreenUpdating = False
Dim myLinks As Variant
myLinks = ActiveWorkbook.LinkSources(Type:=xlLinkTypeExcelLinks)
Sheets("Quote 1").Unprotect "password"
Sheets("Quote 2").Unprotect "password"
Sheets("Quote 3").Unprotect "password"
Sheets("Quote 4").Unprotect "password"
Sheets("Quote 5").Unprotect "password"
For i = 1 To UBound(myLinks)
ActiveWorkbook.BreakLink Name:=myLinks(i), Type:=xlLinkTypeExcelLinks
Next i
Sheets("Quote 1").Protect "password"
Sheets("Quote 2").Protect "password"
Sheets("Quote 3").Protect "password"
Sheets("Quote 4").Protect "password"
Sheets("Quote 5").Protect "password"
Application.ScreenUpdating = True
End Sub
The macro works fine when I run it in the module using F8, however, when I try to run it by clicking F5 or create a button and assign macro to the button and run it, I encounter following error:
"Run-time error '1004':
Method 'Break-Link' of object '_Workbook' failed"
Help in understanding the reason for the error message and suggestions to fix the same would be highly appreciated!
Thanks,
Eraj.
I am working on an Excel file which has 12 sheets in total of which the following 5 sheets only are protected and have links to another excel file. Because of links to another file, the file I am working on is huge in size (about 10 MB).
1. Quote 1
2. Quote 2
3. Quote 3
4. Quote 4
5. Quote 5
So I have written below macro to first unprotect these 5 sheets, then break the links and finally protect the sheets again.
Sub BreakThoseLinks()
Application.ScreenUpdating = False
Dim myLinks As Variant
myLinks = ActiveWorkbook.LinkSources(Type:=xlLinkTypeExcelLinks)
Sheets("Quote 1").Unprotect "password"
Sheets("Quote 2").Unprotect "password"
Sheets("Quote 3").Unprotect "password"
Sheets("Quote 4").Unprotect "password"
Sheets("Quote 5").Unprotect "password"
For i = 1 To UBound(myLinks)
ActiveWorkbook.BreakLink Name:=myLinks(i), Type:=xlLinkTypeExcelLinks
Next i
Sheets("Quote 1").Protect "password"
Sheets("Quote 2").Protect "password"
Sheets("Quote 3").Protect "password"
Sheets("Quote 4").Protect "password"
Sheets("Quote 5").Protect "password"
Application.ScreenUpdating = True
End Sub
The macro works fine when I run it in the module using F8, however, when I try to run it by clicking F5 or create a button and assign macro to the button and run it, I encounter following error:
"Run-time error '1004':
Method 'Break-Link' of object '_Workbook' failed"
Help in understanding the reason for the error message and suggestions to fix the same would be highly appreciated!
Thanks,
Eraj.