replace activex texbox with anything else

mysticmario

Active Member
Joined
Nov 10, 2021
Messages
323
Office Version
  1. 365
Platform
  1. Windows
Hi, I have 365 file which cannot use activeX controls due to co-authoring issue. I have this piece of code where i used activex textbox to store value, which was then used in the subroutine to acheive search functionality. However now i can't seem to figure out how to replace searchbar object(textbox) with for example range("B2")

VBA Code:
Private Sub searchbar_KeyDown(ByVal KeyCode As MSForms.ReturnInteger, ByVal Shift As Integer)
    If KeyCode = vbKeyReturn Then
        Call search_Click
        searchbar.Activate
        
    End If
End Sub

Sub search_Click()
Dim rngFound As Range
With ActiveSheet.Cells
    Set rngFound = .Find(searchbar.Value, After:=ActiveCell _
        , LookIn:=xlFormulas, LookAt:=xlPart, SearchOrder:=xlByRows, _
        SearchDirection:=xlNext, MatchCase:=False, SearchFormat:=False)
    If Not rngFound Is Nothing Then
        rngFound.Select
     
    Else
    MsgBox prompt:="Not found"
    End If
End With
End Sub
any idea how to replace searchbar_KeyDown object with range to maintain the saem functionality?
 

Excel Facts

Can you sort left to right?
To sort left-to-right, use the Sort dialog box. Click Options. Choose "Sort left to right"
I used named range but this doesn't seem to work.
I miss my activeX controls so much, everything was easier with them...
 
Upvote 0
For future readers.
My solution/workaround to this problem was to create a userform which work fine with co-authoring, and made all the objects there.
and then refference them in code:
VBA Code:
Private Sub searchbarwindow_KeyDown(ByVal KeyCode As MSForms.ReturnInteger, ByVal Shift As Integer)
    If KeyCode = vbKeyReturn Then
        Call szukaj_Click
        'wyszukiwarka.searchbarwindow.Activate
        
    End If
End Sub
VBA Code:
Private Sub searchBTN_Click()
Dim rngFound As Range
With ActiveSheet.Cells
    Set rngFound = .Find(wyszukiwarka.searchbarwindow.Value, After:=ActiveCell _
        , LookIn:=xlFormulas, LookAt:=xlPart, SearchOrder:=xlByRows, _
        SearchDirection:=xlNext, MatchCase:=False, SearchFormat:=False)
    If Not rngFound Is Nothing Then
        rngFound.Select
     
    Else
    MsgBox prompt:="Not found"
    End If
End With
End Sub
 
Upvote 0
Hi, I'm having a bit of monologue here but maybe someone may help.
I tried to be clever with userform solution but unfortunately it's bad for my application.
Userform works great and all, however at some point I save all the data to new excel file for further procedures, and that is where my uservform idea fails.
Since when i copy sheet and data to new file usign VBa, unfortunately I do not have my UserForm in this file, therefore the code breaks.
I really need to have somethign to trigger KeyDown event.\
Is there a way to make a keyDown event on a cell?
Normally it just goes to cell below as intended in excel
 
Upvote 0

Forum statistics

Threads
1,214,923
Messages
6,122,289
Members
449,077
Latest member
Rkmenon

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