+ Reply to Thread
Results 1 to 3 of 3

How to add a public subroutine to a class module

  1. #1
    keithb
    Guest

    How to add a public subroutine to a class module

    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



  2. #2
    Chip Pearson
    Guest

    Re: How to add a public subroutine to a class module

    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


    "keithb" <[email protected]> wrote in message
    news:%[email protected]...
    >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
    >




  3. #3
    Jim Thomlinson
    Guest

    RE: How to add a public subroutine to a class module

    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.
    --
    HTH...

    Jim Thomlinson


    "keithb" wrote:

    > 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
    >
    >
    >


+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1