Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
Discussion Groups
General
GeneralPortable MacsHardwareNetworking
Applications
Mac ApplicationsEudoraFirefox / MozillaInternet ExplorerOutlook ExpressMS OfficeEntourageExcelPowerPointWordVirtual PCMedia PlayerOther MS Products
Programming
Mac ProgrammingCodeWarriorPerl
Country Specific
Australian Mac GroupUK Mac Group

Mac Forum / Applications / Excel / May 2008



Tip: Looking for answers? Try searching our database.

finding text in all textboxes

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
LurkingMan - 16 May 2008 17:55 GMT
Hi All:
I'm new to VBA and Excel and have probably made an elementary error, or
several.
I'm trying to retreive  text from all the textboxes (the kind added by the
drawing toolbar) on all the sheets of multiple open workbooks.

I think I've gotten the iteration right, but in the two Subs below, the code
snippet
theText = x.TextFrame.Characters.Text  
seems to not work when x is in a group, even though I'm checking to verify
that x is in fact a text box.

Any help is appreciated. Here's code demonstrating the problem/my confusion.

'Visit all sheets in all open workbooks and call FindTB on each
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 testcode: Getting text from a shape that's a textbox always works here.
               If s.Type = msoTextBox Then
                   xx = s.TextFrame.Characters.Text
                   MsgBox (xx)
               End If

              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  ^^ gets Error 2042 here...
       MsgBox (s.Name)  
'even though the object seems to be the expected text box.

   ElseIf s.Type = msoGroup Then
       Set gs = s.GroupItems
       For i = 1 To gs.Count
           Set x = gs.Item(i)    'so x must be somehow wrong?
           FindTB x
       Next
   End If
End Sub
Signature

In theory, there''s no difference between theory and practice.
In practice, there''s no similarity.

JE McGimpsey - 16 May 2008 20:41 GMT
> Hi All:
> I'm new to VBA and Excel and have probably made an elementary error, or
> several.

I don't see any errors, and the code runs without error for me in
workbooks with both standalone and grouped textboxes.

However, you say the error occurs at the snippet

  theText = x.TextFrame.Characters.Text

yet that snippet doesn't appear anywhere in your code, so there may be
something else going on...

Note that you really don't need to activate anything:

   Public Sub SearchAllTBs2()
       Dim wb As Workbook
       Dim ws As Worksheet
       Dim sh As Shape
       
       For Each wb In Workbooks
           For Each ws In wb.Worksheets
               For Each sh In ws.Shapes
                   GetTBText sh
               Next sh
           Next ws
       Next wb
   End Sub

   Public Sub GetTBText(sh As Shape)
       Dim shGroupItem As Shape
       Select Case sh.Type
           Case msoGroup
               For Each shGroupItem In sh.GroupItems
                   GetTBText shGroupItem
               Next shGroupItem
           Case msoTextBox
               MsgBox sh.Name & vbNewLine & sh.TextFrame.Characters.Text
           Case Else
               'do nothing
       End Select
   End Sub

> I'm trying to retreive  text from all the textboxes (the kind added by the
> drawing toolbar) on all the sheets of multiple open workbooks.
[quoted text clipped - 44 lines]
>     End If
> End Sub
LurkingMan - 16 May 2008 22:28 GMT
HI JE McGimpsey:
Thanks for taking the time to respond to my question.
First off I should have said the code fragment  .TextFrame.Characters.Text,
which I use twice.

My code runs for you??
Your sample code gets a runtime error on my laptop at the same place my code
has a problem.
sh.TextFrame.Characters.Text

Is it possible I'm fighting versioning or installation issues? I tried it on
a co-worker's machine with the same result. I'm on XP with service pack 2 and
excel 2003.

I'm stumped about how to proceed when the code runs elsewhere. Any
suggestions at all?

Signature

In theory, there''''s no difference between theory and practice.
In practice, there''''s no similarity.

> > Hi All:
> > I'm new to VBA and Excel and have probably made an elementary error, or
[quoted text clipped - 88 lines]
> >     End If
> > End Sub
JE McGimpsey - 17 May 2008 00:40 GMT
> My code runs for you??

Yes.

> Your sample code gets a runtime error on my laptop at the same place my code
> has a problem.
> sh.TextFrame.Characters.Text

*WHICH* run-time error?

> Is it possible I'm fighting versioning or installation issues? I tried it on
> a co-worker's machine with the same result. I'm on XP with service pack 2 and
> excel 2003.

Well, you're posting in an XL for Macintosh newsgroup, but as far as I
can tell, it should work fine in XL03 as well.

> I'm stumped about how to proceed when the code runs elsewhere. Any
> suggestions at all?

Is it only in one workbook? Does the same thing happen in a brand new
one?
LurkingMan - 19 May 2008 21:07 GMT
HI JE McGimpsey:
Jeez I don't know how I wound up posting in a different group than I aimed
at, doh.
Since my code has the problem on a brand new spreadsheet with nothing but a
few textboxes on it, I'm going to move my questionto the right discussion
group, because I fear I am dealing with some stupid versioning problem.
Thanks for your help & sorry for the confusion.
Signature

In theory, there''''s no difference between theory and practice.
In practice, there''''s no similarity.

"C" wrote:

> > My code runs for you??
>
[quoted text clipped - 18 lines]
> Is it only in one workbook? Does the same thing happen in a brand new
> one?
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2009 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.