Home |
Search |
Today's Posts |
#1
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
Hi All:
I'm new to VB and Excel, so I may have simply blundered. I'm trying to read text out of a shape that's a text box. ( Is that the right way to describe it? It seems multiple different things are called text boxes.) I use a method that works _sometimes_ and sometimes gives Error 2042. It is s.TextFrame.Characters.Text, where s is tested to be a shape whose .Type is msoTextBox. (Side question: How do I find the meaning of Error 2042 in this context? Searching for "Error 2042" excel gives 9,000 hits wth nothing on the first few pages seeming relevant.) My problem happens on a brand new workbook that has only a few textboxes (some of them grouped) on a worksheet. I succeed in visiting all existing textboxes and can display the name of each. So, what have I done wrong in the following code to make s.Name work and s.TextFrame.Characters.Text not work for the same s? 'Show each sheet of all open workbooks and call FindTB on it. Sub SearchAllTBs() For i = 1 To Workbooks.Count Workbooks(i).Activate For j = 1 To Sheets.Count Worksheets(j).Activate For Each s In ActiveSheet.Shapes ' Some increasingly desperate testcode If s.Type = msoTextBox Then MsgBox (s.TextFrame.Characters.Text) ' Getting text from a shape that's a textbox always works here. FindTB s Next Next j Next i End Sub 'Visit all (shape)text boxes on the active sheet, 'even if they're in a group. Sub FindTB(s) If s.Type = msoTextBox Then xx = s.TextFrame.Characters.Text ' The same line ^^ that worked in the calling function ' gets Error 2042 here and xx is empty, ' but ONLY in a recursive call to FindTB... MsgBox (s.Name) ' even though Name is the name of a text box. 'MsgBox (s.TextFrame.Characters.Text) ' and uncommenting the line above gets Error 13 Type mismatch ElseIf s.Type = msoGroup Then For Each x In s.GroupItems FindTB x Next x End If End Sub -- In theory, there is no difference between theory and practice. In practice, there is no similarity. |
Thread Tools | Search this Thread |
Display Modes | |
|
|
![]() |
||||
Thread | Forum | |||
Center text in a shape textframe | Excel Programming | |||
use VBA to tell if all the text in a TextBox or TextFrame can be displayed | Excel Programming | |||
TextFrame.Characters.Text returns truncated string | Excel Programming | |||
cell to textframe using characters object | Excel Programming | |||
.TextFrame.Characters.Text property readOnly in function?? | Excel Programming |