Skip code if condition is true?

pells

Active Member
Joined
Dec 5, 2008
Messages
361
I am trying to delete workbook links from many workbooks. I have managed to successfully write the code so that the code runs when there is a data link in my workbook, but I dont want to run the code if there isn't any data links. If try to run the code currently on workbook with no links, I get an error saying something on the lines that it cannot find the link - hope this makes sense?

The code I am using to delete the link is as follows:

Workbooks(CurrentWB).BreakLink Name:=(Filelocation & OldWB), Type:=xlExcelLinks

Doesn anyone know if its possible tp skip this part of my module if there aren't any links and continue with the rest of my module? Something on the lines of if Workbooks(CurrentWB).BreakLink Name:=(Filelocation & OldWB), Type:=xlExcelLinks exists then run the rest of code, else skip and continue?

Many thanks for taking the time to read my post and any help would be greatfully received, as I am at a loss a bit here.
 

Excel Facts

Copy formula down without changing references
If you have =SUM(F2:F49) in F50; type Alt+' in F51 to copy =SUM(F2:F49) to F51, leaving the formula in edit mode. Change SUM to COUNT.
Try:
Rich (BB code):
On Error Resume Next
Workbooks(CurrentWB).BreakLink Name:=(Filelocation & OldWB), Type:=xlExcelLinks
On Error Goto 0
 
Upvote 0
Or maybe

Code:
Dim aLinks As Variant
aLinks = Workbooks(CurrentWB).LinkSources(xlExcelLinks)
If Not IsEmpty(aLinks) Then Workbooks(CurrentWB).BreakLink Name:=(Filelocation & OldWB), Type:=xlExcelLinks
 
Upvote 0
Or maybe

Code:
Dim aLinks As Variant
aLinks = Workbooks(CurrentWB).LinkSources(xlExcelLinks)
If Not IsEmpty(aLinks) Then Workbooks(CurrentWB).BreakLink Name:=(Filelocation & OldWB), Type:=xlExcelLinks
Many thanks for this, works perfectly too, so now have 2 options :-)
 
Upvote 0

Forum statistics

Threads
1,224,600
Messages
6,179,834
Members
452,947
Latest member
Gerry_F

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