+ Reply to Thread
Results 1 to 6 of 6

TypeName limitation: How to distinguish Worksheet Variable from Workbook variable

  1. #1
    Forum Contributor
    Join Date
    09-30-2009
    Location
    Barcelona
    MS-Off Ver
    Excel 2010
    Posts
    274

    Question TypeName limitation: How to distinguish Worksheet Variable from Workbook variable

    Hi, I have a function to check if a rangename already exists and I want it to work for both workbook-level and worksheet-level range names

    ideally I'd like to pass either workbook or worksheet as one parameter, and the other with the name as a string

    however I do not see how can the function check if the parameter is a workbook or a worksheet

    typename and vartype return exactly the same for both

    any idea on how to solve elegantly?


    otherwise I'll create two paramters and check which one is missing etc (or a functino to check if is workbook or else)

    thank you!

  2. #2
    Forum Guru JosephP's Avatar
    Join Date
    03-27-2012
    Location
    Ut
    MS-Off Ver
    2003/10
    Posts
    7,328

    Re: TypeName limitation: How to distinguish Worksheet Variable from Workbook variable

    what is the code for which typename returns the same for a worksheet and workbook?
    Josie

    if at first you don't succeed try doing it the way your wife told you to

  3. #3
    Forum Contributor
    Join Date
    09-30-2009
    Location
    Barcelona
    MS-Off Ver
    Excel 2010
    Posts
    274

    Re: TypeName limitation: How to distinguish Worksheet Variable from Workbook variable

    Hi JosephP, this is the code

    Please Login or Register  to view this content.

  4. #4
    Forum Guru JosephP's Avatar
    Join Date
    03-27-2012
    Location
    Ut
    MS-Off Ver
    2003/10
    Posts
    7,328

    Re: TypeName limitation: How to distinguish Worksheet Variable from Workbook variable

    you're not actually initializing your variables so you're passing Nothing for both objects. if you run
    Please Login or Register  to view this content.
    you will see

  5. #5
    Forum Contributor
    Join Date
    09-30-2009
    Location
    Barcelona
    MS-Off Ver
    Excel 2010
    Posts
    274

    Re: TypeName limitation: How to distinguish Worksheet Variable from Workbook variable

    Hi joseph I just realized what you meant
    variables not initialized -- do not refer to any object...

    Typename is useless if variable not initialized, but that is no problem for me

    thank you!

  6. #6
    Forum Guru JosephP's Avatar
    Join Date
    03-27-2012
    Location
    Ut
    MS-Off Ver
    2003/10
    Posts
    7,328

    Re: TypeName limitation: How to distinguish Worksheet Variable from Workbook variable

    you're welcome :-)

    please don't forget to mark the thread solved (click the 'thread tools' link at the top, then 'mark solved')

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

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