How to add a public subroutine to a class module

  • Thread starter Thread starter keithb
  • Start date Start date
K

keithb

I have an add-in containing a class module that is used by a large group of
different spreadsheets. How can I add the following subroutine to the clas
module in a way that it can be called by the individual spreadsheets using a
keypress?

Public Sub shiftRight()
With Selection
.InsertIndent -1
End With
End Sub

Thanks,

Keith
 
You can't assign keys to methods of a class -- you can only
assign keys to regular VBA subs. Therefore, you'd have to write a
regular sub to call the method of your class:

Sub AAA()
If MyObj Is Nothing Then
Set MyObj = New MyClass
End If
MyObj.ShiftRight
End Sub


--
Cordially,
Chip Pearson
Microsoft MVP - Excel
Pearson Software Consulting, LLC
www.cpearson.com
 
I am not really following... Classes have methods which operate on objects
(which are instances of the class). Why not just add a module and place your
sub in that module. The code you posted does not make me think you are trying
to operate on the object you are creating.
 
Back
Top