+ Reply to Thread
Results 1 to 4 of 4

Error 91 when counting and adding commandButton

  1. #1
    Registered User
    Join Date
    04-18-2014
    Location
    Brno
    MS-Off Ver
    Excel 2003
    Posts
    5

    Error 91 when counting and adding commandButton

    Hello,
    i have Userform1 with a few CommandButtons. When i run my VBA code, it return Error 91 - object variable or with block variable not set

    What would i like to do:
    1. I would like to count number of controls on Userform1
    2. I would like to do something with CommandButton1 whitch is placed on Userform1 (change Caption, position ...)

    Please tell me why the Error 91 occurs in this VBA code and how to repair it?

    Please Login or Register  to view this content.
    Thanks for reply
    Last edited by selector; 04-18-2014 at 06:01 AM.

  2. #2
    Forum Expert
    Join Date
    01-23-2013
    Location
    USA
    MS-Off Ver
    Microsoft 365 aka Office 365
    Posts
    3,863

    Re: Error 91 when counting and adding commandButton

    Hi selector,

    Try the following code tested using Excel 2003. However, to actually use the Command Button is a lot more complicated. To do that you probably need a 'Class Module'. See the following (excellent) example, which will probably make your head spin several times.
    http://stackoverflow.com/questions/1...g-vba-on-excel

    Lewis


    Please Login or Register  to view this content.

  3. #3
    Registered User
    Join Date
    04-18-2014
    Location
    Brno
    MS-Off Ver
    Excel 2003
    Posts
    5

    Re: Error 91 when counting and adding commandButton

    Thank you for your answer.
    I find another way to resolve my problem. This code does not return error message and do exactly what i need:

    Please Login or Register  to view this content.
    Last edited by selector; 04-20-2014 at 04:48 AM.

  4. #4
    Forum Expert
    Join Date
    01-23-2013
    Location
    USA
    MS-Off Ver
    Microsoft 365 aka Office 365
    Posts
    3,863

    Re: Error 91 when counting and adding commandButton

    I apologize for misreading your original question. I thought you wanted to add a Control dynamically, not change it's properties.

    The following may help you in the future.

    Lewis

    You can change CommandButton1 properties as follows:
    Please Login or Register  to view this content.
    Another way similar to yours is:
    Please Login or Register  to view this content.


    You may find the following routine useful:
    Please Login or Register  to view this content.
    And finally, if you want to see if a control exists:
    Please Login or Register  to view this content.

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. neede help for creating commandbutton during runtime error
    By aaronkoh in forum Excel Programming / VBA / Macros
    Replies: 16
    Last Post: 01-03-2013, 09:41 AM
  2. Commandbutton in userform to execute code based on a previous commandbutton choice?
    By michaeljoeyeager in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 07-20-2012, 03:28 PM
  3. Commandbutton Error When Cancelled
    By Bluewhistler in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 02-19-2010, 04:29 AM
  4. VBA code for adding a commandbutton
    By ben_sumner in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 02-09-2007, 04:06 AM
  5. [SOLVED] Adding commandbutton to sheet
    By ckoch in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 06-01-2006, 05:10 PM

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