+ Reply to Thread
Results 1 to 5 of 5

How to make sure ActiveWorkbook is not add-in?

  1. #1
    Registered User
    Join Date
    05-25-2011
    Location
    USA
    MS-Off Ver
    Excel 2003 & 2007
    Posts
    3

    How to make sure ActiveWorkbook is not add-in?

    Using Excel 2007, Win7 (but addin will be used on XP/2003 machines as well).

    I keep running into an issue with Excel thinking that the ActiveWorkbook is the one my add-in is in. I NEVER want the add-in to be the activeworkbook. It seems to be intermittent behavior, too. Sometimes the code runs fine. Sometimes it errors because the add-in has become the activeworkbook. In all cases, I have an excel workbook open (besides the "invisible" addin workbook).

    I googled quite a bit on this, came up with nothing.

    Is there a good way to make sure the add-in is not being considered the activeworkbook? I'd like to account for:
    1) Make sure user has SOME workbook open (e.g. not just the Excel app w/ no workbook)
    2) If a workbook (or multiple workbooks) IS open, make sure ActiveWorkbook is not the active one. Is there a way to set active to the workbook that was most recently active? For instance, the one most recentluy opened, or the one most recently clicked on? I dont' want to activate a RANDOM one, you know?

    My preference would be to just make sure the addin is not the activeworkbook; if I can do that without checking other ones being open, etc., I'm very fine with that.

    Thanks for any help with this.

  2. #2
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,643

    Re: How to make sure ActiveWorkbook is not add-in?

    Are you using ActiveWorkbook in code?

    If you are perhaps you could replace it with an explicit workbook reference so the code is looking at the right workbook
    If posting code please use code tags, see here.

  3. #3
    Forum Expert
    Join Date
    02-11-2014
    Location
    New York
    MS-Off Ver
    Excel 365 (Windows)
    Posts
    5,912

    Re: How to make sure ActiveWorkbook is not add-in?

    When you create and install an add-in, the Workbook's IsAddin property is set to True, so it can never be the activeworkbook. It remains part of the Workbooks collection, however. Note that you need to install it as an add-in instead of just opening it (opening instead of installing allows you to edit the workbook part).

    What is the code that is creating the issue?
    Last edited by Bernie Deitrick; 02-18-2014 at 12:50 PM.

  4. #4
    Registered User
    Join Date
    05-25-2011
    Location
    USA
    MS-Off Ver
    Excel 2003 & 2007
    Posts
    3

    Re: How to make sure ActiveWorkbook is not add-in?

    Quote Originally Posted by Bernie Deitrick View Post
    When you create and install an add-in, the Workbook's IsAddin property is set to True, so it can never be the activeworkbook. It remains part of the Workbooks collection, however. Note that you need to install it as an add-in instead of just opening it (opening instead of installing allows you to edit the workbook part).

    What is the code that is creating the issue?

    Ah, it's possible this is the issue. I am always able to edit and save the code, which I believes means I have it open as a workbook, even though it IS an addin being used (I use the addin's custom Excel ribbon menu items to test the code in break mode, so I know it's being used as an addin), so perhaps this will not happen when I actually close the vba editor and run as a user would using menus only and no break mode.

    I will test this and get back with all of you. Thanks, everyone, for the responses, I appreciate it.

  5. #5
    Forum Expert
    Join Date
    02-11-2014
    Location
    New York
    MS-Off Ver
    Excel 365 (Windows)
    Posts
    5,912

    Re: How to make sure ActiveWorkbook is not add-in?

    Note that you can install an add-in and still make changes to the code from the VBE. If you are using a sheet in the add-in as either a template or a data storage sheet, then to make changes to the sheet you just change the IsAddin property to False, go to Excel and make the changes, then set IsAddin back to True and save the workbook.

+ 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] ActiveWorkBook
    By Pete in forum Excel General
    Replies: 7
    Last Post: 10-23-2013, 11:43 PM
  2. using activeworkbook and thisworkbook.
    By D_Rennie in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 07-03-2009, 10:41 AM
  3. Different between ActiveWorkbook.Sheet and ActiveWorkbook.WorkSheets
    By Ranjani in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 04-02-2009, 12:56 AM
  4. [SOLVED] 'ActiveWorkbook.Names.Add Name:' how to make range variable?
    By TeeSea in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 06-09-2005, 11:05 AM
  5. ActiveWorkbook SaveAs
    By Mike in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 02-11-2005, 12:06 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