Activate a TextBox at worksheet load; Excel 2016

AbstractCure

New Member
Joined
Sep 11, 2017
Messages
2
Somehow I'm getting Run-time error 438 Object doesn't support this property or method. The code is placed in "ThisWorkbook" in a VBA project in Excel 2016, but I had this issue even Excel 2013 ever since I created this workbook.

Private Sub Workbook_Open()
ActiveWorkbook.Worksheets("User card").Activate
ActiveWorkbook.Worksheets("User card").SearchBox.Activate
End Sub


The idea is to activate a TextBox called "SearchBox" when the Excel file is open. The error happens at the line where SearchBox.Activate is. Also, the error only pops up when the Excel file was previously saved with anything entered in the "SearchBox" text box. If it was saved with a blank SearchBox, then the error doesn't show.
So, I decided to empty the text box before activating it:

Private Sub Workbook_Open()
ActiveWorkbook.Worksheets("User card").Activate
ActiveWorkbook.Worksheets("User card").SearchBox.Text = ""
ActiveWorkbook.Worksheets("User card").SearchBox.Activate
End Sub

... and now I'm getting the same error at the line SearchBox.Text = ""
... but if the workbook was saved with an empty SearchBox, then the error doesn't happen.

Do you have a way of activating a textbox that actually works?

Thank you!
 

Excel Facts

When did Power Query debut in Excel?
Although it was an add-in in Excel 2010 & Excel 2013, Power Query became a part of Excel in 2016, in Data, Get & Transform Data.
.
What happens if you SELECT the textbox , instead of ACTIVATE ?

Code:
[COLOR=#333333]ActiveWorkbook.Worksheets("User card").SearchBox.Select[/COLOR]
 
Upvote 0
I had more time this evening to review your code in your first post.

Your code works as desired here. So , I'm not certain what is occurring on your end that is preventing the code from functioning as desired.

????
 
Upvote 0

Forum statistics

Threads
1,223,227
Messages
6,170,849
Members
452,361
Latest member
d3ad3y3

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