Page 1 of 2 12 LastLast
Results 1 to 10 of 17
Like Tree1Likes

Is there an API for VBA like there is for Java?

This is a discussion on Is there an API for VBA like there is for Java? within the General Excel Discussion & Other Questions forums, part of the Question Forums category; My only programming experience is with Java, and with basic knowledge of coding and logic from that, I'm teaching myself ...

  1. #1
    New Member
    Join Date
    Feb 2014
    Posts
    29

    Default Is there an API for VBA like there is for Java?

    My only programming experience is with Java, and with basic knowledge of coding and logic from that, I'm teaching myself VBA. My biggest, biggest, biggest frustration is that I have no clue where to look to learn the syntax and language! I can imagine the flow of code perfectly in my mind, but I just don't know how to write it out.

    Ideally there would be some sort of document like this but I'm beginning to believe that doesn't exist for VBA. I've found this page but it doesn't seem to be complete.

    For instance, right now I'm trying to figure out how to link a range to a listbox to populate it from, and I've been Googling around and trying every snippet of code I find to no avail. If there was just a page somewhere that listed all the properties and methods you can call on the listbox class, I'd be golden. But that just doesn't seem to be out there.

    Am I just using the reference guide wrong? Are the answers I'm looking for hidden in that page? If not... where in the hell do people go to learn the language??

    You can imagine how frustrated I'm getting. I really appreciate any direction on this.

  2. #2
    MrExcel MVP
    Moderator
    xenou's Avatar
    Join Date
    Mar 2007
    Location
    Clev. OH, USA
    Posts
    15,099

    Default Re: Is there an API for VBA like there is for Java?

    Hi,

    Yes and no.

    For core VBA itself, the VBA help file doesn't seem to have many fans but I actually used it a lot when learning vba. Just hit the F1 key. If you highlight a word, it takes you to a context sensitive page. For instance, highlighting a function name or object name gets you the help on that item. [Note: I find it is best if you *don't* use online resources for help - the local help file is usually more concise and more relevant, whereas online you never know what they will try to feed you as content. There is some setting for this buried deep in Excel options.]

    I highly recommend VB and VBA in a Nutshell by Paul Lomax. It's a concise compendium of all VBA functions including some related resources like the Scripting library, with clear examples and also explanation of common pitfalls to watch out for. Cheap used copies were available last time I checked.

    Microsoft seems to be changing up it's web pages (again). I can't seem to find a plain vanilla developers reference. It exists somewhere. TechOnTheNet seems to have copied it too, so you can find the same articles googling their site.

    Also there is more than one definition of VBA here - you need to learn the Excel Object Model if you are programming Excel. For learning specifically about how to use Excel Objects in VBA then the link you gave is actually an excellent place to go. And of course reading books and the rest of the usual tips about getting better with Excel VBA programming. I like the Wrox series called the Excel VBA Programmers Reference for learning Excel VBA programming - it's got great explanations of key topics for getting your way around in Excel VBA, and old versions will do in a pinch if you want to save some money - many of the basics are still unchanged.
    Last edited by xenou; Mar 6th, 2014 at 04:24 PM.

    Using: Office 2007/Win7 (work) Office 2010/Win7 (home)

    You are rich in proportion to the number of things you can let alone.
    -- Henry David Thoreau

  3. #3
    MrExcel MVP
    Moderator
    RoryA's Avatar
    Join Date
    May 2008
    Location
    UK
    Posts
    29,381

    Default Re: Is there an API for VBA like there is for Java?

    To see what properties, methods and events a given class exposes, the Object Browser in the VB Editor is ideal - just press f2.

  4. #4
    New Member
    Join Date
    Feb 2014
    Posts
    29

    Default Re: Is there an API for VBA like there is for Java?

    zenou-
    The help file has been extremely hit or miss for me. Sometimes it shows me exactly what I need, sometimes, just as with the reference page, it's incomplete and doesn't list the method I'm looking for.

    I was just now able to get a few books from someone, and they have been somewhat helpful (although, the problem I'm currently working on, and have been for literally the last 4 hours still isn't solved ). But still none of them list the actual language so I don't feel like I'm getting anywhere.

    Maybe I'm going at this from the wrong angle. I just want to see the language, and I feel like I'll be able to piece together everything before that through trial and error. That could be a mistake, that could be jumping the gun, but hell, until I have the language I won't know if that's true.


    RoryA-
    This seems like it could be the right path. Half of it just seems like another version of the reference page I linked to. But then there's a long list of "Xl---" stuff. Following that, I found XlFormControl>XlListBox, but then, where are the methods you can call on a ListBox? Maybe this isn't designed to answer that question. So then how/what would I use it for? Seeing that ListBox is a FormControl is all well and dandy, but again that doesn't get me anywhere closer to knowing the language and calling methods.


    You guys have pointed me in a couple of directions for a wealth of knowledge and I thank you for that. I'm still just sitting here utterly flabbergasted that Microsoft doesn't have the language listed anywhere online, or if they do, it's F***ING BURIED on MSDN. Seriously, even if the language is listed elsewhere online or in books... where did the publishers of that content get the language from? This just isn't making sense to me.

  5. #5
    Board Regular
    Join Date
    Jan 2013
    Posts
    227

    Default Re: Is there an API for VBA like there is for Java?

    Quote Originally Posted by UWMmakow View Post
    zenou-
    The help file has been extremely hit or miss for me. Sometimes it shows me exactly what I need, sometimes, just as with the reference page, it's incomplete and doesn't list the method I'm looking for.
    Microsoft's documentation is seldom incomplete. And in the few instances that it is it's not recommended that developers use undocumented methods. I think it's just unclear what you should be looking for. You keep mentioning that you want documentation for the VBA language, but you're really looking for documentation for the library you're using.

    For example, you mentioned something about a ListBox, which you would find here: Microsoft Forms Visual Basic Reference
    The problem with that particular documentation is that it's a bit confusing because everything is considered a "control" and they share a lot of the same methods.

  6. #6
    MrExcel MVP
    Moderator
    xenou's Avatar
    Join Date
    Mar 2007
    Location
    Clev. OH, USA
    Posts
    15,099

    Default Re: Is there an API for VBA like there is for Java?

    Post a question about the practical problem you are facing It's unclear exactly what kind of object you are working with - listbox in a userform? In a worksheet? Forms control or ActiveX control? There are many objects in the Excel programming world. From what it sounds like when you say "For instance, right now I'm trying to figure out how to link a range to a listbox to populate it from" you wouldn't even do this in code. The simplest and most effective way is to pull up the Listbox properties and provide the range address. But it makes a diffference what kind of listbox because Excel can use both "Forms" control (which are "native" excel widgets, so to speak), and ActiveX controls, which are "generic" forms controls and have a richer event model and can more easily be programmatically controlled.

    Note that it is true as AngelJ says that you need to be very clear when you talk about VBA - the base language is not very complicated. But it is enriched by the "host application" that is is being paired with - so suddenly at that point you have the whole range of complex applications such as databases, spreadsheet, email clients, userforms, and so on. So that involves getting to know the "Object Model" of the host application. Suddenly it's getting complicated! I think that in general MS does have good object model references online, but I admit I have yet to browse even the complete Excel object model, and I've been programming to it for something like 7 years or more.

    Note that I will agree with you that this is a very pathetic page (following AngelJ's link into the form controls objects to the listbox object): http://msdn.microsoft.com/en-us/libr...ice.14%29.aspx
    Basically it says "a listbox is a control that lists things"

    So I am not unsympathetic to your complaints - but it is possible to learn what you need to know.
    Last edited by xenou; Mar 6th, 2014 at 08:59 PM.

    Using: Office 2007/Win7 (work) Office 2010/Win7 (home)

    You are rich in proportion to the number of things you can let alone.
    -- Henry David Thoreau

  7. #7
    MrExcel MVP
    Moderator
    RoryA's Avatar
    Join Date
    May 2008
    Location
    UK
    Posts
    29,381

    Default Re: Is there an API for VBA like there is for Java?

    The Object Browser has a search box at the top so you could just type in ListBox and look at the results. There's a brief highlights page here: Excel Matters The Object Browser

  8. #8
    Board Regular
    Join Date
    Jan 2013
    Posts
    227

    Default Re: Is there an API for VBA like there is for Java?

    Quote Originally Posted by xenou View Post
    Note that I will agree with you that this is a very pathetic page (following AngelJ's link into the form controls objects to the listbox object): ListBox Control
    Basically it says "a listbox is a control that lists things"
    Yeah, I've always been so impressed with Microsoft's documentation so that was a real letdown. I think they tried to make up for it with all the articles under "concepts", but that still doesn't really cut it.

  9. #9
    New Member
    Join Date
    Feb 2014
    Posts
    29

    Default Re: Is there an API for VBA like there is for Java?

    Well guys I'm glad to see some discussion on this. I was pretty frustrated yesterday so today I'm thinking a bit more clearly. Thanks for bearing with me.

    I'm sure that since I'm going at this "sideways", just trying to teach myself and brute force my way through everything, I've missed some core concepts and that's where my inaccurate language is coming from. And a good deal of my confusion, no doubt.

    The problem that I'm working on now: I've got a listbox (Forms) on a sheet which, depending on which of 2 option buttons is selected, will either display data from one range or another. This might not even be the best way to accomplish what I"m trying to do:

    This is a workbook for data entry by date. The option button is to choose between monthly or weekly. The listbox has the date options in it, so it'll either be linked to a range of months, or a range of 52 weeks. Now I could just put two listboxes on top of eachother and bring the correct one forward, but I feel like there should be a better way to do it.

    Anyways I thought the correct code was something along the lines of
    Code:
    Sheets("Input").MonthOrWeekList.RowSource = range
    , but obviously not.

  10. #10
    Board Regular
    Join Date
    Jan 2013
    Posts
    227

    Default Re: Is there an API for VBA like there is for Java?

    In that case, it sounds like you need the List property of the ListBox object, and the Value property of the Range object. Something like this:
    Code:
    Sheets("Input").MonthOrWeekList.List = Range("A2:A4").Value
    Edit: Also, based on the libraries you're using, for documentation I would use the Object Browser and the Help feature (F1) as others have suggested, rather than the reference on MSDN.
    Last edited by AngelJ; Mar 7th, 2014 at 04:06 PM.
    Norie likes this.

Page 1 of 2 12 LastLast

Like this thread? Share it with others

Like this thread? Share it with others

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  


DMCA.com