+ Reply to Thread
Results 1 to 3 of 3

Create variable number of userforms in separate workbook

Hybrid View

Eatmybrain Create variable number of... 06-23-2020, 12:00 PM
ByteMarks Re: Create variable number of... 06-23-2020, 12:42 PM
Eatmybrain Re: Create variable number of... 06-24-2020, 10:57 AM
  1. #1
    Registered User
    Join Date
    08-13-2015
    Location
    Wiltshire, England
    MS-Off Ver
    2010
    Posts
    15

    Create variable number of userforms in separate workbook

    Hi

    I need to create a variable number of userforms at runtime to provide the user with a list of questions. These will be selected by a previous userform.

    So the Level 1 form will determine which Level 2 questions are asked. The level 2 questions will be shown in blocks of 10 to the user for their answers, the answers need to be saved between opening and closing the file so I will pass the answers to a worksheet. The user needs to be able to move back and forth through the userforms in order to answer some questions at a later date.

    My plan is to dynamically create the userforms based on the answers to the level 1 questions, pass the answers to a sheet and pass them back to the form the next time it is created.

    So far I run the macro, create a new workbook (wbDest) and copy over the modules and references from the original workbook, then call the macro to create the userforms in the new workbook (wbDest).

    The below code generates a runtime error 75 path/file not found when creating the userform, I need to solve this as I need the level 2 userforms to have different names in order to pass the answers back to the userform in the correct order, on subsequent uses. If it makes a difference in the code the object references are all Public

    Dim frmQuestionsL1 As VBComponent
    Dim lbLabel As MSForms.Label
    Dim wbDest As Workbook
    Dim r As Long
    
    Set frmQuestionsL1 = wbDest.VBProject.VBComponents.Add(vbext_ct_MSForm)
    
    With frmQuestionsL1
        .Properties("Height") = 274
        .Properties("Width") = 608.5
        .Properties("Caption") = "Level 1 Questions"
        .Properties("BackColor") = RGB(255, 255, 255)
        .Properties("BorderStyle") = fmBorderStyleNone
        .Properties("ForeColor") = RGB(0, 41, 121)
        .Properties("Font").Value.Item("Name") = "Calibri"
        .Properties("Font.Size").Value.Item("Size") = 10
        .Properties("SpecialEffect") = fmSpecialEffectFlat
        .Name = "frmQuestionsL1" ' ***ERROR OCCURS HERE***
    End With
    Many thanks in advance for your help!
    Last edited by Eatmybrain; 06-23-2020 at 12:09 PM.

  2. #2
    Forum Expert ByteMarks's Avatar
    Join Date
    07-23-2018
    Location
    UK
    MS-Off Ver
    O365 32bit (Windows)
    Posts
    3,280

    Re: Create variable number of userforms in separate workbook

    The name is still a property, so it should be
    .Properties("Name") = "frmQuestionsL1"
    Also, I think .Properties("Font.Size").Value.Item("Size") = 10 should be
    .Properties("Font").Value.Item("Size") = 10

  3. #3
    Registered User
    Join Date
    08-13-2015
    Location
    Wiltshire, England
    MS-Off Ver
    2010
    Posts
    15

    Re: Create variable number of userforms in separate workbook

    Thanks for your help ByteMarks, I have made the changes and the code now progresses past the .Name line, however it then immediately reverts to the following line (which calls the macro from the original workbook)

    strTemp = wbDest.Name
    
    Application.Run "'" & strTemp & "'!start_assessment"
    I'm not sure why this happens, I've used this technique before to call macros across multiple workbooks from one master workbook, so unsure why it would back track like this?

+ 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. Replies: 7
    Last Post: 02-19-2017, 02:43 PM
  2. Create a separate workbook using data from another workbook.
    By macro_noob3030 in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 01-04-2017, 10:54 AM
  3. Create Separate Workbook and Move any previous versions
    By cmore in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 02-12-2014, 08:23 AM
  4. Macro for copying & inserting a variable number of rows into a separate workbook
    By Gunther Maplethorpe in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 11-01-2013, 06:26 PM
  5. Replies: 4
    Last Post: 10-09-2013, 06:26 PM
  6. UserForms: Creating variable number of text boxes
    By seckela in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 06-11-2012, 05:46 PM
  7. Create pivottable in separate workbook with ptcache
    By Martin Los in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 10-06-2005, 08:05 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