+ Reply to Thread
Results 1 to 3 of 3

Accessing userform by variable name

  1. #1
    Registered User
    Join Date
    09-21-2010
    Location
    vancouver
    MS-Off Ver
    Excel 2003
    Posts
    3

    Accessing userform by variable name

    The code below works ok if named user form isn't open-active. If I was to create a button in that user form with below code to execute when button pushed, I receive an error at line
    "For Each CNTRL In ThisWorkbook.VBProject.VBComponents(FormName).Designer.Controls"
    Error: "Object variable or with block variable not set"
    Again, code works perfect if run with form closed; not when actively opened.
    Need to work with form opened.


    Please Login or Register  to view this content.

  2. #2
    Forum Moderator - RIP Richard Buttrey's Avatar
    Join Date
    01-14-2008
    Location
    Stockton Heath, Cheshire, UK
    MS-Off Ver
    Office 365, Excel for Windows 2010 & Excel for Mac
    Posts
    29,464

    Re: Accessing userform by variable name

    Hi,

    Try instead

    For Each CNTRL In UserForm1.Controls
    ....etc..
    Richard Buttrey

    RIP - d. 06/10/2022

    If any of the responses have helped then please consider rating them by clicking the small star icon below the post.

  3. #3
    Registered User
    Join Date
    09-21-2010
    Location
    vancouver
    MS-Off Ver
    Excel 2003
    Posts
    3

    Re: Accessing userform by variable name

    Not answering the question; Accomplish your example with a variable substitution for the userform1 name. I don't want to call the object by name; I want to call it using a variable like in my example (FormName)
    The code needs to be used against other forms

+ 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. [SOLVED] Problems with accessing the VBA from UserForm
    By Szwadron6 in forum Excel Programming / VBA / Macros
    Replies: 16
    Last Post: 05-12-2017, 04:33 AM
  2. [SOLVED] Accessing public variable from form
    By JasonLeisemann in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 06-12-2015, 12:41 PM
  3. VBA Userform accessing Access
    By popfan in forum Excel Programming / VBA / Macros
    Replies: 8
    Last Post: 11-21-2011, 11:54 AM
  4. Accessing variables assigned in one userform by a second userform?
    By jerseyguy1996 in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 11-30-2009, 04:12 PM
  5. Accessing an Excel Form procedure from a UserForm
    By excelhelp456 in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 07-01-2009, 07:56 AM
  6. [SOLVED] Accessing a variable(a range) and modifying it
    By James Cornthwaite in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 05-30-2006, 06:10 PM
  7. [SOLVED] Accessing DropDown box from a Userform
    By Stephen English in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 01-14-2005, 08:06 AM

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