Consulting

Results 1 to 3 of 3

Thread: Automatically add code to ThisWorkbook

  1. #1

    Question Automatically add code to ThisWorkbook

    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:
    [VBA]' Allow only me to open the file in a read/write
    If Not Application.UserName = "usernamehere" Then
    ThisWorkbook.ChangeFileAccess xlReadOnly
    End If
    End Sub[/VBA]
    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?

  2. #2
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    What workbook event?

  3. #3
    VBAX Regular Smitty's Avatar
    Joined
    Jun 2004
    Location
    Boulder Creek, CA
    Posts
    30
    Location
    Check out Chip Pearson's Programming To The Visual Basic Editor

    Hope that helps,

    Smitty

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •