PDA

View Full Version : Solved: How to unlink a TextBox linked to a cell in a worksheet



limetoad
06-06-2013, 12:32 PM
I'm using Excel 2010, trying to filter through all TextBoxes in a worksheet and test if they are linked to a cell. Then, if they are linked I want to remove the link while keeping the text that was in the TextBox before unlinking it... This is the general idea:

For Each sh In ActiveSheet.Shapes
If Left([wherever the link address is stored], 1) = "=" Then [remove link]
Next sh

Any ideas?

p45cal
06-06-2013, 01:33 PM
perhapsFor Each sh In ActiveSheet.TextBoxes
If Len(sh.Formula) > 1 Then sh.Formula = Empty
Next sh

limetoad
06-06-2013, 03:44 PM
When I try that I get the following error: "Object doesn't support this property or method".

snb
06-06-2013, 03:44 PM
for each it in activesheet.oleobjects
if it.object.linkedcell<>"" then it.object.linkedcell=""
next

limetoad
06-06-2013, 04:08 PM
for each it in activesheet.oleobjects
if it.object.linkedcell<>"" then it.object.linkedcell=""
next

I tried something like this before, but as I'm F8'ing through the code it doesn't even read that one, as soon as it reads the first line it jumps over the rest of the for loop and continues with the rest of the code... Is there a reference that I need to add, or something else I am missing?

snb
06-07-2013, 12:37 AM
You didn't tell us what kind of textboxes you are using (formcontrols, activeX controls, etc).
A sample workbook can do miracles....

limetoad
06-07-2013, 08:03 AM
Good point snb, I actually have no idea what kind of textbox it is... So here is a sample of what I'm working with.

limetoad
06-07-2013, 08:16 AM
It doesn't look like it let me attach the file, it said it was uploading, but it's not there... Anyways, the text box is whatever is the standard for Excel 2010... I just selected Insert>Text Box.

p45cal
06-07-2013, 08:55 AM
It doesn't look like it let me attach the file, it said it was uploading, but it's not there... You have to have a minimum post count - don't know what it is (5?)






Anyways, the text box is whatever is the standard for Excel 2010... I just selected Insert>Text Box.I've just tried this in Excel 2010 and my code in Msg#2 works fine. Are you sure you've used ActiveSheet.TextBoxes in the first line?

limetoad
06-07-2013, 03:21 PM
You have to have a minimum post count - don't know what it is (5?)





I've just tried this in Excel 2010 and my code in Msg#2 works fine. Are you sure you've used ActiveSheet.TextBoxes in the first line?
p45cal, you're right, I just had to use something other than "sh" for your code (see below), since I had already set "sh" as a Shape. Thanks!

Dim tb as Variant
For Each tb In ActiveSheet.TextBoxes
If Len(tb.Formula) > 1 Then tb.Formula = Empty
Next tb