Solved

Textbox autocompletion using values from a column of an Excel sheet with VSTO

Posted on 2009-07-07
3
988 Views
Last Modified: 2013-11-10
Hi,

I'm developing an Excel add-in, and I'd like to parameterize the autocompletesource of a Textbox to use values from the column of a worksheet.

The problem is that the Excel file is always opened by the user and so I cannot use it as a data source with a standard connection.

I'd like to not reload all the values on each display of the textbox because it can become very long. Is there a way to use an opened Excel spreadsheet as a data source?

Or would it be possible to bind a DataTable on an opened Excel spreadsheet , and update it by detecting any modification in the sheet?

Thanks,
Julien
0
Comment
Question by:JulienVan
3 Comments
 
LVL 3

Accepted Solution

by:
TiranDagan55 earned 500 total points
ID: 24793817
Take a look at this external link with a solution:
http://www.mrexcel.com/forum/showthread.php?t=31107

Option Explicit

Dim oRange As Range

Dim iCharCount As Integer

Dim sAuto As String

Dim sTemp As String
 
 

Private Sub EnteredName_Enter()

  Set oRange = Worksheets("Sheet1").Range("a35536").End(xlUp).Offset(1, 0)

End Sub
 

Private Sub MyAutoComplete(ByRef oTextbox As Control)

  oRange.Value = oTextbox.Text

  sAuto = oRange.AutoComplete(oTextbox.Text)
 

  If Len(sAuto) > 0 Then

    With oTextbox

      sTemp = .Text

      .Text = sAuto

      .SelStart = Len(sTemp)

      .SelLength = Len(sAuto)

    End With

  End If

End Sub
 

Private Sub EnteredName_Exit(ByVal Cancel As MSForms.ReturnBoolean)

'++++++++++++++++++++++++++++++++++++

'Change this next line if you are going to hard code which cell gets the data

  Sheets("Sheet1").Range("a1").Value = Me.EnteredName.Text

'++++++++++++++++++++++++++++++++++++

  oRange.ClearContents

End Sub
 

Private Sub EnteredName_Keyup(ByVal KeyCode As MSForms.ReturnInteger, ByVal Shift As Integer)

  If KeyCode >= 48 And KeyCode <= 90 Then  'Alphanumeric only

    Application.EnableEvents = False

    MyAutoComplete Me.EnteredName

    Application.EnableEvents = True

  End If

End Sub

Open in new window

0
 
LVL 2

Author Comment

by:JulienVan
ID: 24794223
Thanks, I didn't think about the autocompletion of Excel, it is a very good idea.
I'll try this solution and come back after to tell you if it's working in my case.
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Entity Framework is a powerful tool to help you interact with the DataBase but still doesn't help much when we have a Stored Procedure that returns more than one resultset. The solution takes some of out-of-the-box thinking; read on!
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
The viewer will learn how to create a normally distributed random variable in Excel, use a normal distribution to simulate the return on an investment over a period of years, Create a Monte Carlo simulation using a normal random variable, and calcul…
Many functions in Excel can make decisions. The most simple of these is the IF function: it returns a value depending on whether a condition you describe is true or false. Once you get the hang of using the IF function, you will find it easier to us…

920 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now