PDA

View Full Version : Automatically add code to ThisWorkbook



MrRhodes2004
08-17-2006, 09:07 AM
I have files that I create that I share with others. Due to the office situation making the files read only doesn't work for some people and IT isn't of help. So I wrote the following code:
' Allow only me to open the file in a read/write
If Not Application.UserName = "usernamehere" Then
ThisWorkbook.ChangeFileAccess xlReadOnly
End If
End Sub
This opens the file read only and does what I need.
I have a tool bar (xla add-in) that I have created that is used by several other engineers. I would like this function made available to them by just clicking a button.
I would like the code to determine the username and add it to the "usernamehere". Then add all of the code to the current workbook they are working in, ThisWorkbook module.

How do I go about writing the code that will create new code in ThisWorkbook module?

Bob Phillips
08-17-2006, 10:24 AM
What workbook event?

Smitty
08-20-2006, 09:19 AM
Check out Chip Pearson's Programming To The Visual Basic Editor (http://www.cpearson.com/excel/vbe.htm)

Hope that helps,

Smitty