LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 459
Default Referencing A Subprocedures Name (Re-post)

Try this as a demo:

1. Create a new blank workbook. By default the first sheet is
codename'd Sheet1.
2. From the Controls Toolbox toolbar, add an ActiveX textbox to
Sheet1. Place it 'inside' cell B2.
3. Create a new class module, named Class1 by default, and paste in
the following code:

'<Code in class module named Class1--------
Option Explicit

Private WithEvents m_oTextBox As MSForms.TextBox
Private m_oRange As Excel.Range

Public Function Init( _
ByVal MSFormsTextBox As MSForms.TextBox, _
ByVal ExcelRange As Excel.Range _
) As Boolean

Set m_oTextBox = MSFormsTextBox
Set m_oRange = ExcelRange

Init = True

End Function

Private Sub m_oTextBox_Change()
Convert
End Sub

Private Function Convert() As Boolean
Dim intTest As Integer
On Error Resume Next
intTest = CInt(m_oTextBox.Text)
If Err.Number = 0 Then
m_oRange.Value = intTest
Else
m_oRange.Value = "Error!"
End If
On Error GoTo 0
End Function
'</Code in class module named Class1-------

4. Paste the following code to the ThisWorkbook code module:

'<Code in ThisWorkbook code module--------
Option Explicit

Private c As Class1

Private Sub Workbook_Open()
Set c = New Class1
c.Init Sheet1.TextBox1, Sheet1.Range("A2")
End Sub
'</Code in ThisWorkbook code module-------

5. Run the Workbook_Open sub (either save, close and reopen the
workbook, or just run it from the VBE).

6. Type in the textbox. If the text is an integer it will be shown in
cell A2, otherwise an error message will appear. You can delete/insert
rows above/below row2 and the functionality still works.

--

"Bryn" wrote in message ...
Here is the original post if it is of any help!

//////////////////////////////////////////////////////////

Here is an example of a subprocedure I am using... it is
used to convert an input into an integer.

Private Sub TextBox41_Change()

Dim linkedCell As String, cellValue As String

linkedCell = TextBox41.linkedCell

cellValue = TextBox41.Value

Call convert(linkedCell, cellValue)

End Sub

However, I am wanting to reference the name of the
subprocedure in which this code is being ran... so
instead
of having to type:

linkedCell = TextBox41.linkedCell

cellValue = TextBox41.Value

which is textbox specific I can simply reference the name
of the textbox through the sub's name, after having
deleted
the _Click part previous to the remaining code, ie.
something like

linkedCell = "sub.name".linkedCell

cellValue = "sub.name".Value

I have over 100 of these text boxes to edit and I dont
want
to be having to paste in all this code only to have to go
in and individually change the textbox numbers
specfically
for each textbox!

Thanks for any help.

Bryn.

 
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
Before my first post crehan57 About this forum 0 September 18th 10 08:56 PM
will this post jaci Excel Discussion (Misc queries) 2 February 11th 09 07:43 PM
referencing a different tab by referencing a list in the current s Kevin Excel Worksheet Functions 3 July 6th 07 07:57 PM
Should I generally request "post a poll" when I post a new thread? Joe Miller Excel Discussion (Misc queries) 2 January 7th 06 04:46 PM
Referencing a Subprocedures Name No Name Excel Programming 2 February 25th 04 09:35 AM


All times are GMT +1. The time now is 04:07 AM.

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"