+ Reply to Thread
Results 1 to 3 of 3

using activeworkbook and thisworkbook.

  1. #1
    Valued Forum Contributor
    Join Date
    05-14-2009
    Location
    gold coast
    MS-Off Ver
    Excel 2007
    Posts
    843

    using activeworkbook and thisworkbook.

    I noticed all the code that i have on a userform using activeworkbook will relate to whatever the last active workbook was "who would have guessed hay"
    Seeing thisworkbook used a lot i decided to go through the whole project and change all activeworkbook too thisworkbook.sheet1
    During this i also made a few other changes that i was confident in, When i run it now it errors on the thisworkbook.sheet1.
    Is this the wrong way of using thisworkbook to make sure the code always deals with the correct file. (will this ever be affected if the file goes through a Save As)
    Or is it during my over conifedents that i have made a error somewhere else and the debuger is point me here cos it hates me.

    Thankyou all
    Last edited by D_Rennie; 07-03-2009 at 10:41 AM.

  2. #2
    Forum Guru romperstomper's Avatar
    Join Date
    11-04-2008
    Location
    A1
    MS-Off Ver
    Most
    Posts
    12,302

    Re: using activeworkbook and thisworkbook.

    ThisWorkbook will always refer to the workbook containing the code.
    Sheet1 is an (implicitly created) variable - it is not a property of the ThisWorkbook object. You therefore just use Sheet1 in the code, not ThisWorkbook.Sheet1 (the variable has only project level scope so it can only refer to Sheet1 in the workbook with the code.)
    Remember what the dormouse said
    Feed your head

  3. #3
    Valued Forum Contributor
    Join Date
    05-14-2009
    Location
    gold coast
    MS-Off Ver
    Excel 2007
    Posts
    843

    Re: using activeworkbook and thisworkbook.

    Thanks again.

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

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