+ Reply to Thread
Results 1 to 3 of 3

Dynamically add code for a object using Macro

  1. #1
    Registered User
    Join Date
    07-31-2010
    Location
    Mumbai
    MS-Off Ver
    Excel 2003
    Posts
    1

    Dynamically add code for a object using Macro

    Dear All,
    I am a beginner to VBA.
    The situation is -:
    When i click on a button in a existing sheet (A), a new sheet opens.
    Apart from all the formatting etc, I am addding a Check box in this new sheet.
    I want to assign a macro to this checkbox and want to store it in that workbook itself.
    While i am able to access the checkbox using the following statement below -:
    newWorkSheet.Shapes("Check Box 1").Select


    In the Selection.OnAction I want to direct it to a peice of code which i have written but i am unable to transfer it to the new workbook.

    Because this excel program has to be used by many people, i am not inclined to use the following code, becuase it requries them to enable the macro security setting of "Trust accesss to VBA project object model"

    **** NOT WANTING TO USE THE FOLLOWING CODE*******
    'Dim FName As String
    'With Workbooks("AuctionRequestForm- Draft 3")
    'FName = .Path & "\code.txt"
    '.VBProject.VBComponents("Module1").Export FName
    'End With
    'ActiveWorkbook.VBProject.VBComponents.Import FName

    **** NOT WANTING TO USE THE ABOVE CODE*******

    Is there a way, I can dynamically type the peice of code in the new workbook?

    I tried using ActiveWorkbook.VBProject.VBComponents.Add vbext_ct_StdModule, however, i am unable to do it.


    Kindly help.

  2. #2
    Forum Expert shg's Avatar
    Join Date
    06-20-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2003, 2010
    Posts
    40,678

    Re: Dynamically add code for a object using Macro

    Welcome to the forum.

    Please take a few minutes to read the forum rules, and then edit your post to add CODE tags.

    Thanks.
    Last edited by shg; 07-31-2010 at 01:07 AM.
    Entia non sunt multiplicanda sine necessitate

  3. #3
    Forum Expert dominicb's Avatar
    Join Date
    01-25-2005
    Location
    Lancashire, England
    MS-Off Ver
    MS Office 2000, 2003, 2007 & 2016 365
    Posts
    4,867

    Smile Re: Dynamically add code for a object using Macro

    Your post does not comply with Rule 8 of our Forum RULES. Cross-posting is when you post the same question in other forums on the web. You'll find people are disinclined to respond to cross-posts because they may be wasting their time solving a problem that has been solved elsewhere. We prefer that you not cross-post at all, but if you do (and it's unlikely to go unnoticed), you MUST provide a link (copy the url from the address bar in your browser)to the cross-post. Expect cross-posts without a link to be closed a message will be posted by the moderator explaining why. We are here to help so help us help you!

    Read this to understand why we ask you to do this

    http://www.mrexcel.com/forum/showthread.php?t=484910

    DominicB
    Please familiarise yourself with the rules before posting. You can find them here.

+ 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