+ Reply to Thread
Results 1 to 5 of 5

Add In writes VBA at runtime to new workbook. How do I reference the add in?

  1. #1
    Registered User
    Join Date
    01-01-2023
    Location
    Earth
    MS-Off Ver
    Office 365
    Posts
    2

    Add In writes VBA at runtime to new workbook. How do I reference the add in?

    Hi Forum Members,

    TL/DR: How do I reference a worksheet from an add-in in the workbook_open code of a workbook created at run time?


    I have an add in that creates a new workbook and, in addition to creating a report, writes code to object modules (both the sheets and the ThisWorkbook Workbook_Open event).

    I copy a worksheet from the add in, called Permissions, that sets the parameters for the user (what they can access and what they can update on the new file). One field that I reference is basically a show/hide of some sensitive data.

    I have the worksheet set to very hidden and the users are not really sophisticated with VBA so that *should* suffice.

    However, I would like to further protect this data by *not* importing the permissions sheet. I would like to keep it in the add in and then reference it from the workbook_open event.

    Using pseudo-code,

    instead of:
    boolSensitiveData = ActiveWorkbook.Sheets(Permissions.Name).Cells(1,1)

    replace with:
    boolSensitiveData = AddIn.Sheets(Permissions.Name).Cells(1,1)

    This will dynamically capture user security/permission changes in addition to providing an extra layer of security.

    How do I reference the add in in the workbook_open code?

    The user sets the path of the entire system at creation time, but the add in can be in a different location. I would prefer not to maintain a separate file and restricting access, but will do so. That would entail opening the permissions file with the _open event, get what is needed, and then closing the file. I do that with the data, but want to keep some stuff secret.
    Last edited by TheVillageIdiot; 03-11-2024 at 07:36 PM.

  2. #2
    Valued Forum Contributor
    Join Date
    02-02-2016
    Location
    Indonesia
    MS-Off Ver
    Office 365
    Posts
    1,004

    Re: Add In writes VBA at runtime to new workbook. How do I reference the add in?

    How do I reference the add in in the workbook_open code?
    Try using its filename (without the path):
    Please Login or Register  to view this content.

  3. #3
    Forum Guru Andy Pope's Avatar
    Join Date
    05-10-2004
    Location
    Essex, UK
    MS-Off Ver
    O365
    Posts
    20,436

    Re: Add In writes VBA at runtime to new workbook. How do I reference the add in?

    Use Thisworkbook, which is a reference to the workbook containing the code being executed.
    Cheers
    Andy
    www.andypope.info

  4. #4
    Registered User
    Join Date
    01-01-2023
    Location
    Earth
    MS-Off Ver
    Office 365
    Posts
    2

    Re: Add In writes VBA at runtime to new workbook. How do I reference the add in?

    Quote Originally Posted by Akuini View Post
    Try using its filename (without the path):
    Please Login or Register  to view this content.
    Thank you. This seems to work nicely.

  5. #5
    Valued Forum Contributor
    Join Date
    02-02-2016
    Location
    Indonesia
    MS-Off Ver
    Office 365
    Posts
    1,004

    Re: Add In writes VBA at runtime to new workbook. How do I reference the add in?

    You're welcome, glad to help & thanks for the feedback.

+ 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. Missing reference vs unchecked reference runtime
    By Kyle123 in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 12-14-2018, 05:12 AM
  2. [SOLVED] Runtime 1004: The sort reference is not valid.
    By ElStar in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 10-31-2018, 03:39 AM
  3. [SOLVED] how to 'set reference to scripting.runtime'
    By dschmitt in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 12-10-2015, 02:54 AM
  4. [SOLVED] Display cell reference - runtime error type mismatch
    By Brumbot in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 04-19-2013, 06:44 AM
  5. [SOLVED] How to refer to the workbook where the macro when another workbook is open during runtime?
    By jonelamora in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 09-04-2012, 11:21 PM
  6. Runtime error 9 when trying to reference another workbook
    By MingVBA in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 06-30-2011, 08:48 PM
  7. Set addin reference at runtime.
    By MattShoreson in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 05-08-2006, 08:10 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