LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 4
Default why does s.TextFrame.Characters.Text work only sometimes?

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
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Center text in a shape textframe DaveL Excel Programming 4 May 19th 08 04:50 PM
use VBA to tell if all the text in a TextBox or TextFrame can be displayed [email protected] Excel Programming 1 March 15th 07 04:26 AM
TextFrame.Characters.Text returns truncated string Dennis Excel Programming 2 October 1st 06 11:23 PM
cell to textframe using characters object Simon Prince Excel Programming 3 February 25th 04 06:10 AM
.TextFrame.Characters.Text property readOnly in function?? VB_Help Excel Programming 1 August 27th 03 05:16 PM


All times are GMT +1. The time now is 06:14 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"