+ Reply to Thread
Results 1 to 6 of 6

How to restrict code to current workbook

  1. #1
    Registered User
    Join Date
    03-22-2010
    Location
    Ballarat, Australia
    MS-Off Ver
    Excel 2003
    Posts
    31

    How to restrict code to current workbook

    Hi

    I have the following code linked to a drop down list in my workbook

    Please Login or Register  to view this content.

    It populates textboxes on the sheet with a lookup value result, the lookup value is taken from the dropdown box. The problem I have is any other excel workbooks that are open at the same time, the code is trying to run against those workbooks when I edit them, I can't seem to restrict the code to run only against the workbook in which the dropdown box which the code is linked to, exists in. I have tried moving the code to a module in the workbook but then the code does not seem to work as it does know which workbook the combo box and text boxes which should be filled with the lookuip result belong in

    Link to workbook is below

    https://www.dropbox.com/sh/x1i4yl9ju...sVSuZ6bLatBiTa
    Last edited by alansidman; 08-03-2014 at 10:36 PM. Reason: code tags added

  2. #2
    Forum Moderator alansidman's Avatar
    Join Date
    02-02-2010
    Location
    Steamboat Springs, CO
    MS-Off Ver
    MS Office 365 Version 2405 Win 11 Home 64 Bit
    Posts
    23,882

    Re: How to restrict code to current workbook

    Code Tags Added
    Your post does not comply with Rule 3 of our Forum RULES. Use code tags around code.

    Posting code between [CODE]Please [url=https://www.excelforum.com/login.php]Login or Register [/url] to view this content.[/CODE] tags makes your code much easier to read and copy for testing, it also maintains VBA formatting.

    Highlight your code and click the # icon at the top of your post window. More information about these and other tags can be found at http://www.excelforum.com/forum-rule...rum-rules.html



    (Because you are new to the forum, I have added them for you today. Please take a few minutes to read all Forum Rules and comply in the future.)
    Alan עַם יִשְׂרָאֵל חַי


    Change an Ugly Report with Power Query
    Database Normalization
    Complete Guide to Power Query
    Man's Mind Stretched to New Dimensions Never Returns to Its Original Form

  3. #3
    Forum Contributor
    Join Date
    10-30-2013
    Location
    Melbourne
    MS-Off Ver
    Excel 2013
    Posts
    173

    Re: How to restrict code to current workbook

    The code as written will not work in a standard module because the ComboBox is a member of the module of the worksheet where it apears.

    To resolve which Workbook to reference, you need to fully qualify Sheets.

    Replace all references to Sheets with ThisWorkbook.Sheets.


    Sent from my iPad using Tapatalk

  4. #4
    Registered User
    Join Date
    03-22-2010
    Location
    Ballarat, Australia
    MS-Off Ver
    Excel 2003
    Posts
    31

    Re: How to restrict code to current workbook

    So do I put the code in a module and modify as per below

    Please Login or Register  to view this content.

  5. #5
    Forum Expert Vikas_Gautam's Avatar
    Join Date
    06-04-2013
    Location
    Ludhiana,Punjab, India
    MS-Off Ver
    Excel 2013
    Posts
    1,850

    Re: How to restrict code to current workbook

    Try this..

    Please Login or Register  to view this content.
    Don't forget to click *

  6. #6
    Registered User
    Join Date
    03-22-2010
    Location
    Ballarat, Australia
    MS-Off Ver
    Excel 2003
    Posts
    31

    Re: How to restrict code to current workbook

    Great - yep that did it

+ 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. [SOLVED] Opening new workbook and pasting values into current workbook - code issues
    By Stew1234 in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 05-15-2014, 07:56 AM
  2. [SOLVED] Code that finds and deletes names from current sheet to all worksheets in workbook
    By grazian2 in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 08-01-2013, 11:51 AM
  3. VBA code to copy data from specific worksheets from current workbook to a new one
    By Uday2013 in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 07-01-2013, 12:15 PM
  4. VBA Code Excel restrict user emailing a workbook
    By Ronsco in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 12-12-2011, 05:03 AM
  5. Place code from current workbook to new workbook
    By Qaspec in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 06-08-2005, 11:05 AM

Tags for this Thread

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