VBA Code dynamically written to worksheets not working when project is protected

janullrich18

New Member
Joined
Sep 26, 2013
Messages
2
Hey Guys,

My problem:

I have a userform launched on the workbook open event for the user to input the names and tech data for a range of fans. For example, they enter 5 fans. Once they enter the data into the form and click start, 5 sheets named,for example Fan1, Fan2.... to Fan5 are dynamically created and the user form closes. The start button click sub on the form also involves a part to write code to each worksheet module for a worksheet change event. Everything works fine when the VBproject is not locked, as soon as I lock it and go through the exact same process, I get an error on the

Code:
ThisWorkbook.VBProject.VBComponents("Sheet" & IntSheetCount).CodeModule.AddFromString StrWorksheetChangeCode

Any ideas on why this happens?

Cheers
 

Excel Facts

Create a chart in one keystroke
Select the data and press Alt+F1 to insert a default chart. You can change the default chart to any chart type
Hi Jan.

I have a pretty good idea oif what might be the problem and actually I am thinking you could work it out too.

Your question is something like "I have a room in my house. Normally I can open the door and walk in to it. Today I locked the door with the key. Now when I try to turn the handle and open the door, I can't. Does anybody know why ?"

After a little reflection, I think you might be able to answer your own question. :)

Cheers,

Warren K.
 
Upvote 0
haha, yeah. When you put it like that it sounds like my question is a stupid one. Maybe what I should have asked is "is it impossible to write code to a module when the project is locked, or is there a workaround?"

Hi Jan.

I have a pretty good idea oif what might be the problem and actually I am thinking you could work it out too.

Your question is something like "I have a room in my house. Normally I can open the door and walk in to it. Today I locked the door with the key. Now when I try to turn the handle and open the door, I can't. Does anybody know why ?"

After a little reflection, I think you might be able to answer your own question. :)

Cheers,

Warren K.
 
Upvote 0

Forum statistics

Threads
1,214,618
Messages
6,120,544
Members
448,970
Latest member
kennimack

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top