+ Reply to Thread
Results 1 to 10 of 10

Why Worksheets(1) is an Object ?

  1. #1
    Registered User
    Join Date
    02-04-2018
    Location
    Tehran
    MS-Off Ver
    2016
    Posts
    5

    Why Worksheets(1) is an Object ?

    I am wonder why in excel VBA , Worksheets(1) returns an Object(variant) .
    I expected that returning type will be a Worksheet object.

  2. #2
    Forum Guru xladept's Avatar
    Join Date
    04-14-2012
    Location
    Pasadena, California
    MS-Off Ver
    Excel 2003,2010
    Posts
    12,378

    Re: Why Worksheets(1) is an Object ?

    Have you answered your own question?
    If I've helped you, please consider adding to my reputation - just click on the liitle star at the left.

    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~(Pride has no aftertaste.)

    You can't do one thing. XLAdept

    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~aka Orrin

  3. #3
    Forum Guru xlnitwit's Avatar
    Join Date
    06-27-2016
    Location
    London
    MS-Off Ver
    Windows: 2010; Mac: 16.13 (O365)
    Posts
    7,085

    Re: Why Worksheets(1) is an Object ?

    Hi

    Macro sheets are also part of the Worksheets collection.
    Don
    Please remember to mark your thread 'Solved' when appropriate.

  4. #4
    Registered User
    Join Date
    02-04-2018
    Location
    Tehran
    MS-Off Ver
    2016
    Posts
    5

    Re: Why Worksheets(1) is an Object ?

    Have you answered your own question?

    I don't know answer . and I want to figure out how VBA designer think about worksheets.
    Last edited by farshid_mi; 02-04-2018 at 06:25 PM.

  5. #5
    Registered User
    Join Date
    02-04-2018
    Location
    Tehran
    MS-Off Ver
    2016
    Posts
    5

    Re: Why Worksheets(1) is an Object ?

    Macro sheets are also part of the Worksheets collection.
    No, If you have a macro sheet , you can not access it in worksheets collection. you can test it and see the following code doesn't show macro sheet name:

    Please Login or Register  to view this content.
    (I know sheets is a collection contains all sheets type like chart sheet , macro sheet , ... )
    Last edited by farshid_mi; 02-04-2018 at 06:28 PM.

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

    Re: Why Worksheets(1) is an Object ?

    How are you getting Object from Worksheets(1)?

    When I try this in the Immediate Window it returns Worksheet.
    Please Login or Register  to view this content.
    If posting code please use code tags, see here.

  7. #7
    Registered User
    Join Date
    02-04-2018
    Location
    Tehran
    MS-Off Ver
    2016
    Posts
    5

    Re: Why Worksheets(1) is an Object ?

    Quote Originally Posted by Norie View Post
    How are you getting Object from Worksheets(1)?

    When I try this in the Immediate Window it returns Worksheet.
    Please Login or Register  to view this content.
    If you type worksheets(1) , the list member dose not show . when VBE can not recognize object type it happens also you can see the tool tip when typing "Worksheets( " , in the tool tip you can see "_Default(index) as object " .
    (I know that we can define a variable as worksheet to access member list in VBE but I want to figure out why worksheets(1) tool tip says it return Object and why we can not access its list member in VBE)
    Last edited by farshid_mi; 02-04-2018 at 07:10 PM.

  8. #8
    Forum Expert shg's Avatar
    Join Date
    06-20-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2003, 2010
    Posts
    40,678

    Re: Why Worksheets(1) is an Object ?

    Intellisense doesn't appear because the Worksheets method can return either a single worksheet (with all the usual properties or methods) or an array of worksheets, which have their own methods (like FillAcrossSheets)

    That's why it's convenient to assign a worksheet variable.
    Last edited by shg; 02-04-2018 at 08:37 PM.
    Entia non sunt multiplicanda sine necessitate

  9. #9
    Registered User
    Join Date
    02-04-2018
    Location
    Tehran
    MS-Off Ver
    2016
    Posts
    5

    Re: Why Worksheets(1) is an Object ?

    Quote Originally Posted by shg View Post
    Intellisense doesn't appear because the Worksheets method can return either a single worksheet (with all the usual properties or methods) or an array of worksheets, which have their own methods (like FillAcrossSheets)

    That's why it's convenient to assign a worksheet variable.
    Thanks ,,,,,,,,,,,

  10. #10
    Forum Guru xlnitwit's Avatar
    Join Date
    06-27-2016
    Location
    London
    MS-Off Ver
    Windows: 2010; Mac: 16.13 (O365)
    Posts
    7,085

    Re: Why Worksheets(1) is an Object ?

    Quote Originally Posted by farshid_mi View Post
    No, If you have a macro sheet , you can not access it in worksheets collection.
    You are correct. Apologies- my memory failed me there.

+ 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. errors with Worksheets object
    By bsapaka in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 09-26-2014, 09:01 PM
  2. Replies: 0
    Last Post: 06-19-2014, 02:09 PM
  3. View Object disabled for Excel worksheets
    By paul12d in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 10-11-2011, 02:20 AM
  4. [SOLVED] Worksheets() Object
    By dallin in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 08-12-2006, 10:10 PM
  5. method Worksheets of object _Global failed
    By ndalal in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 05-02-2006, 09:30 AM
  6. Different Behaviour of Public Object Vars in Worksheets vs. Add-In
    By Etienne in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 01-04-2006, 10:20 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