unable to access .text property textbox on worksheet (office 365)

liw

New Member
Joined
Apr 22, 2020
Messages
4
Office Version
  1. 365
Platform
  1. Windows
Hi all,

Somehow got myself commited to creating a kind of user form in excel (didn't go the 'userform' route, however) I am using activex textboxes (and comboboxes).
I have essentially zero experience and by now I am stumped on how to proceed.

I have a number of boxes (18 - ordered in six 'lines' of three boxes: one to specify a file, one to define a name and one to define a label) that (dis)appear based on the value chosen in a combobox. That works. What I can't get to work is clearing any text entered in these boxes when they are set to invisible.

Here is the code I use to make the optional boxes (dis)appear based on the value entered for a combobox named 'nvarlistmenu'

VBA Code:
Private Sub nvarlistmenu_Change()
   
    Dim topvals(6) As Integer
        
    For i = 1 To 6
        topvals(i) = 106 + ((i - 1) * 49.5)
    Next
    
    Dim basenames(3) As Variant    
    basenames(1) = "kernbestandvar"
    basenames(2) = "namevar"
    basenames(3) = "labelvar"
        
   If nvarlistmenu.Value = "nee" Then
        Rows("7:24").EntireRow.Hidden = True
        
        For b = 1 To 3
        For i = 1 To 6
        boxname = basenames(b) & i
        ActiveSheet.Shapes(boxname).Visible = False
        
        Next i
        Next b
        
    ElseIf nvarlistmenu.Value = "ja, 6" Then
        Rows("7:24").EntireRow.Hidden = False
        
        For b = 1 To 3
        For i = 1 To 6
        boxname = basenames(b) & i
        ActiveSheet.Shapes(boxname).Visible = True
        ActiveSheet.Shapes(boxname).Top = topvals(i)
        Next i
        Next b

etc etc.


Now for clearing the boxes: i can't seem to access the .text property in the same manner as the .visible and .top properties.
Something like this:
VBA Code:
Private Sub namevar4_Change()
 namevar4.Text = "test"
End Sub
... works perfecty fine to alter the text to 'test' whenever one types in that specific box. But that clearly is not what I am after here.

Within the loops shown above, simply accessing .text doesn't work. Based on info here and elsewhere on the net I suspect I need something along the lines of:

VBA Code:
    With ActiveSheet.Shapes(boxname).TextFrame
    .Characters.Text = ""
    End With

Except: I can't figure out precisely what I need. I tried all kinds of combinations of .textframe, .textframe2, .character, .textrange, .text, .value and am flat out of luck so far. Of all the possible things I've tried, the one posted seems to get me the farthest: the error message (error 438: object doesn't support this property or method) is active for the .characters.text line, giving me the impression that at least the "With ActiveSheet.Shapes(boxname).TextFrame"-bit is working/accepted.

If anyone could help me solve this, I'd be super grateful!!
 

Excel Facts

Best way to learn Power Query?
Read M is for (Data) Monkey book by Ken Puls and Miguel Escobar. It is the complete guide to Power Query.
How about like
VBA Code:
   With ActiveSheet.OLEObjects(boxname)
      .Visible = False
      .Object.Text = "abc"
   End With
 
Upvote 0
Wooopdiwoop! It cost me a day and a half but I seem to have figured it out at last!!!

ActiveSheet.Shapes(boxname).OLEFormat.Object.Object.Value = ""

In context:
VBA Code:
    ElseIf nvarlistmenu.Value = "ja, 5" Then
        Rows("7:21").EntireRow.Hidden = False
        Rows("22:24").EntireRow.Hidden = True

        For b = 1 To 3
        For i = 1 To 5
        boxname = basenames(b) & i
        ActiveSheet.Shapes(boxname).Visible = True
        ActiveSheet.Shapes(boxname).Top = topvals(i)
        Next i

        For i = 6 To 6
        boxname = basenames(b) & i
        ActiveSheet.Shapes(boxname).OLEFormat.Object.Object.Value = ""
        ActiveSheet.Shapes(boxname).Visible = False
        Next i
        Next b
 
Upvote 0
Oh Mr (or Ms) Fluff, we just cross posted. Yet yours is way more pleasing to the eye so I'll test and implement if it works (think it should, though perhaps it might need an added .object).
 
Upvote 0
VBA Code:
    ElseIf nvarlistmenu.Value = "ja, 5" Then
        Rows("7:21").EntireRow.Hidden = False
        Rows("22:24").EntireRow.Hidden = True

        For b = 1 To 3
        For i = 1 To 5
        boxname = basenames(b) & i
        
            With ActiveSheet.OLEObjects(boxname)
                .Visible = True
                .Top = topvals(i)
            End With
            
        Next i

        For i = 6 To 6
        boxname = basenames(b) & i
        
            With ActiveSheet.OLEObjects(boxname)
               .Visible = False
               .Object.Value = ""
            End With
        
        Next i
        Next b


[The End]
 
Upvote 0
Glad to help & thanks for the feedback
 
Upvote 0

Forum statistics

Threads
1,223,231
Messages
6,170,884
Members
452,364
Latest member
springate

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top