+ Reply to Thread
Results 1 to 14 of 14

Finding LineStyle options

  1. #1
    Forum Contributor
    Join Date
    04-09-2013
    Location
    City, World
    MS-Off Ver
    Office 365
    Posts
    248

    Finding LineStyle options

    Hi
    Range-->Borders-->LineStyle is a property and it takes several options (numbers) like XLdash, XLdotdash etc

    My question, using object browser, how can I know what LineStyle options are?

    I know there is Enum under "Classes" list called XLLineStyle and if I open that I will see all the options for lineStyle but my question

    How can I know there is XlineStyle? In the object browser, when I clicked on Range-->Borders-->LineStyle, I only read this "Property LineStyle As Variant"

    See attached screen shot. How am I supposed to know LineStyle options are in Enum called XLLineStyle. What is the rule or the logic I should use to search for LineStyle options once I see it defined as property, not only LineStyle but any other properties. For example Range-->Borders-->Weight ? Thank you very much.
    Attached Images Attached Images
    Last edited by lastnn30; 05-18-2021 at 10:38 PM.

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

    Re: Finding LineStyle options

    Look for it in Class rather than member:

    Capture.JPG
    Last edited by Bernie Deitrick; 05-13-2021 at 02:41 PM.
    Bernie Deitrick
    Excel MVP 2000-2010

  3. #3
    Forum Contributor
    Join Date
    04-09-2013
    Location
    City, World
    MS-Off Ver
    Office 365
    Posts
    248

    Re: Finding LineStyle options

    Thank you. I found it but my question how do I know there is a Enum called XLLineStyle and that Enum has all the value for the LineStyle property of object Borders?
    The same thing apply on XLborderWeight. How do I know there is such one?

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

    Re: Finding LineStyle options

    That's just how object oriented languages work (which is what VBA is) - if there is a property that exists, it will have assigned values that are allowed, even if they are just True and False. Just use F2 to open the object browser and search for the class of interest. If you are searching for a value that gets assigned to a property, it will be show as a member of that class.
    Last edited by Bernie Deitrick; 05-13-2021 at 03:25 PM.

  5. #5
    Forum Contributor
    Join Date
    04-09-2013
    Location
    City, World
    MS-Off Ver
    Office 365
    Posts
    248

    Re: Finding LineStyle options

    Thanks. if you see my screenshot above, Borders has a property called LineStyle. Now when I click on LineStyle, I will read at the bottom of the windows that LineStyle is a property of type Variant. So far so good. Now for a new vba user like me. I can not go further than that. Object Browser stop right there. How can I know (using object browser) that I can assign any member of XLLineStyle Enum to be a value of the LineStyle. Let me say it in another word, how can I find the link between LineStyle and XLLineStyle? I found it by google etc but how about other properties in different objects etc. That is my question. I was hoping if I click on LineStyle, somehow a text would be appear and say: "you need to go to XLLineStyle and to find which value you can assign" That is my question actually. Thank you very much.

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

    Re: Finding LineStyle options

    When you search for a term - in the VBE, press F2 - look for a class that includes the word that you are searching on that that starts with Xl. For LineStyle, there is one, called XlLineStyle - that is the naming convention used by Excel. So if you want to see all the class that have members just search on Xl - there are a lot of them, but it is instructive to see. VBA was not developed for hand-holding new programmers, and it is a hard thing to learn - I learn new things all the time, and I started VBA with Excel 95 - so over 25 years ago.

  7. #7
    Forum Contributor
    Join Date
    04-09-2013
    Location
    City, World
    MS-Off Ver
    Office 365
    Posts
    248

    Re: Finding LineStyle options

    Thank you for your help. I updated the post and I attached a screen shot of the Object Browser. Please see above. Thanks once again

  8. #8
    Forum Expert rorya's Avatar
    Join Date
    08-13-2008
    Location
    East Sussex, UK
    MS-Off Ver
    365 Ent Monthly Channel / Insiders Beta
    Posts
    8,903

    Re: Finding LineStyle options

    To your question, there is no direct way for you to know that (and Excel doesn't expect you to know anything). You have to either do what Bernie suggested, or perhaps record a macro assigning a specific linestyle or weight and then search for those items in the OB. The issue arises in situations like this because a range can be multiple cells and therefore have different borders applied to the cells within it. That means that the property has to be able to return Null and to do that it needs to return a Variant type rather than the Enum normally associated with it.
    Rory

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

    Re: Finding LineStyle options

    When you run into that last section "LineStyle As Variant" just do another, more specific search for that - you start with Borders and end up at LineStyle, then progress to LineStyle and find XlLineStyle.... It's all a process.

  10. #10
    Forum Contributor
    Join Date
    04-09-2013
    Location
    City, World
    MS-Off Ver
    Office 365
    Posts
    248

    Re: Finding LineStyle options

    Thank you all. yes that is what I want to do actually

    "then progress to LineStyle and find XlLineStyle"

    How can I progress when I do not see any hint in the Object Browser telling me I need to assign one value from the Enum XLLineStyle?

    Same thing with

    Range("a1").VerticalAlignment = xlTop

    How can I know that VerticalAlignment takes one value of XLTopBottom Enum? Object Browser does not suggest I need to go to XLToptBottom to find out these values. That is my question. Does Microsoft really want people to guess and trial and error to find the right values? Thank you again.

  11. #11
    Forum Expert rorya's Avatar
    Join Date
    08-13-2008
    Location
    East Sussex, UK
    MS-Off Ver
    365 Ent Monthly Channel / Insiders Beta
    Posts
    8,903

    Re: Finding LineStyle options

    Search for xlTop and you should find that it is part of an Enumeration...

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

    Re: Finding LineStyle options

    Welcome to the Excel Object Model. It's a very long learning process made simpler by recording macros and editing them to contain the core element that you want - in this case, the vertical alignment set to xlTop - and removing the stuff that you don't need. Go from this:

    Please Login or Register  to view this content.
    to this:
    Please Login or Register  to view this content.
    OR, more generally, to one of these:
    Please Login or Register  to view this content.

  13. #13
    Forum Contributor
    Join Date
    04-09-2013
    Location
    City, World
    MS-Off Ver
    Office 365
    Posts
    248

    Re: Finding LineStyle options

    Quote Originally Posted by rorya View Post
    Search for xlTop and you should find that it is part of an Enumeration...
    That is my problem or my question.. How do I know I need to search for XLTop?

  14. #14
    Forum Expert rorya's Avatar
    Join Date
    08-13-2008
    Location
    East Sussex, UK
    MS-Off Ver
    365 Ent Monthly Channel / Insiders Beta
    Posts
    8,903

    Re: Finding LineStyle options

    It’s in the code line you posted.

+ 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] Finding an exact match from multiple options
    By orion23 in forum Excel Formulas & Functions
    Replies: 12
    Last Post: 02-20-2020, 02:51 PM
  2. [SOLVED] Bug? VBA Border.LineStyle=1 cannot be set
    By klaas1952 in forum Excel Programming / VBA / Macros
    Replies: 14
    Last Post: 05-31-2016, 10:20 AM
  3. [SOLVED] Borders.LineStyle = xlContinuous
    By top_dog in forum Excel Programming / VBA / Macros
    Replies: 9
    Last Post: 10-05-2015, 04:32 PM
  4. What is linestyle?
    By ammartino44 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 05-27-2015, 06:41 PM
  5. [SOLVED] Case options, finding a value, copying the value to the left and pasting on new sheet.
    By emilyloz in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 07-30-2013, 01:42 PM
  6. [SOLVED] Conditional Formatting Macro .LineStyle = xlContinuous error
    By Smeddlesboy in forum Excel Programming / VBA / Macros
    Replies: 9
    Last Post: 12-26-2012, 09:53 AM
  7. How do I get VBA to copy the MajorGridlines.Border.LineStyle into a variable
    By revector in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 07-30-2008, 02:33 PM

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