Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Need VBA Code to Select text boxes in spreadsheet

I have a spreadsheet (Excel 2003) of data copied from a web page that has
critical data contained in a column of 400 text boxes. I need to remove the
text boxes from the spreadsheet, but retain the data. So far, I have been
able to address the text boxes one at a time from VBA and extract the data,
but I need to know how to address them from within the code. The text boxes
are named HTMLText1 through HTMLText400. I can generate the names using a
For loop, but using them to address the text boxes stumps me.

Dim strThisBoxName As String
Dim intValue As Integer
Dim g As Integer

For g = 1 To 1
strThisBoxName = "HTMLText" & g
intValue = [strThisBoxName].Value
Cells(g, "L").Value = intValue
Next g

returns an Invalid Qualifier error on the intValue = ... line.

Dim thisbox As textbox
Dim strThisBoxName As String
Dim intValue As Integer
Dim g As Integer

For g = 1 To 1
strThisBoxName = "HTMLText" & g
Set thisbox = Me.[strThisBoxName]
intValue = thisbox.Value
Cells(g, "L").Value = intValue
Next g

returns a "Needs Object" error on the Set thisbox... line.

I hope from the code, someone can see what I am trying to do and supply the
correct syntax to accomplish it.

Thank you in advance.
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 131
Default Need VBA Code to Select text boxes in spreadsheet

I imagine your textboxes may be activex controls, in which case this should
work:

For g = 1 To 400
Cells(g, "L").Value = _
ActiveSheet.OLEObjects("HTMLText" & g).Object.Text
Next g

If somehow they were Shapes on your sheet, this should do it:

Dim g As Long
Dim myShp As Shape
Dim CharCount As Long

For g = 1 To 1
Set myShp = ActiveSheet.Shapes("HTMLText" & n)
CharCount = shp.TextFrame.Characters.Count
Cells(g, "L").Value = shp.TextFrame.Characters(1, CharCount).Text
Next g

Set myShp = Nothing


"Jaded in Cali" wrote:

I have a spreadsheet (Excel 2003) of data copied from a web page that has
critical data contained in a column of 400 text boxes. I need to remove the
text boxes from the spreadsheet, but retain the data. So far, I have been
able to address the text boxes one at a time from VBA and extract the data,
but I need to know how to address them from within the code. The text boxes
are named HTMLText1 through HTMLText400. I can generate the names using a
For loop, but using them to address the text boxes stumps me.

Dim strThisBoxName As String
Dim intValue As Integer
Dim g As Integer

For g = 1 To 1
strThisBoxName = "HTMLText" & g
intValue = [strThisBoxName].Value
Cells(g, "L").Value = intValue
Next g

returns an Invalid Qualifier error on the intValue = ... line.

Dim thisbox As textbox
Dim strThisBoxName As String
Dim intValue As Integer
Dim g As Integer

For g = 1 To 1
strThisBoxName = "HTMLText" & g
Set thisbox = Me.[strThisBoxName]
intValue = thisbox.Value
Cells(g, "L").Value = intValue
Next g

returns a "Needs Object" error on the Set thisbox... line.

I hope from the code, someone can see what I am trying to do and supply the
correct syntax to accomplish it.

Thank you in advance.

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2
Default Need VBA Code to Select text boxes in spreadsheet

Neither of those strategies worked. The OLE version returned an error: OLE
Object not found. The ActiveX version returned a similar error.

Clicking on Properties for the boxes, they are listed as HTMLText objects.
Visual Basic allowed me to Dim the ThisBox variable as "HTMLText" and
provides a HTMLText.value property, but I could not figure out how to address
the boxes using the loop variable.

Any clues would be greatly appreciated.

Thanks to all.

Reply
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
how to select multiple text boxes in excel for formatting Rob New Users to Excel 3 April 2nd 23 08:38 PM
Cannot select text boxes SMarie2834 Excel Discussion (Misc queries) 1 November 8th 06 08:18 PM
How to select all hidden text boxes Manish M Kankaria Excel Discussion (Misc queries) 2 January 12th 06 09:51 AM
Text boxes in Spreadsheet Ann Excel Programming 6 November 21st 05 05:55 PM
Select text boxes code Nicky[_2_] Excel Programming 2 January 27th 04 10:57 PM


All times are GMT +1. The time now is 06:08 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"