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

UWMmakow

New Member
Joined
Feb 25, 2014
Messages
29
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.
 

Some videos you may like

Excel Facts

Can you AutoAverage in Excel?
There is a drop-down next to the AutoSum symbol. Open the drop-down to choose AVERAGE, COUNT, MAX, or MIN

xenou

MrExcel MVP, Moderator
Joined
Mar 2, 2007
Messages
16,676
Office Version
2013
Platform
Windows
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:

RoryA

MrExcel MVP, Moderator
Joined
May 2, 2008
Messages
35,174
Office Version
365, 2019, 2016, 2010
Platform
Windows, MacOS
To see what properties, methods and events a given class exposes, the Object Browser in the VB Editor is ideal - just press f2.
 

UWMmakow

New Member
Joined
Feb 25, 2014
Messages
29
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 :banghead:). 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.
 

AngelJ

Board Regular
Joined
Jan 8, 2013
Messages
226
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.
 

xenou

MrExcel MVP, Moderator
Joined
Mar 2, 2007
Messages
16,676
Office Version
2013
Platform
Windows
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/library/office/gg251523(v=office.14).aspx
Basically it says "a listbox is a control that lists things" :eek:

So I am not unsympathetic to your complaints - but it is possible to learn what you need to know.
 
Last edited:

RoryA

MrExcel MVP, Moderator
Joined
May 2, 2008
Messages
35,174
Office Version
365, 2019, 2016, 2010
Platform
Windows, MacOS
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
 

AngelJ

Board Regular
Joined
Jan 8, 2013
Messages
226
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" :eek:
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.
 

UWMmakow

New Member
Joined
Feb 25, 2014
Messages
29
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.
 

AngelJ

Board Regular
Joined
Jan 8, 2013
Messages
226
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:

Watch MrExcel Video

Forum statistics

Threads
1,102,777
Messages
5,488,781
Members
407,658
Latest member
Arias610

This Week's Hot Topics

  • Timer in VBA - Stop, Start, Pause and Reset
    [CODE=vba][/CODE] Option Explicit Dim CmdStop As Boolean Dim Paused As Boolean Dim Start Dim TimerValue As Date Dim pausedTime As Date Sub...
  • how to updates multiple rows in muliselect listbox
    Hello everyone. I need help with below code. code is only chaning 1st row in mulitiselect list box. i know issue with code...
  • Delete Row from Table
    I am trying to delete a row from a table using VBA using a named range to find what I need to delete. My Range is finding the right cell. In the...
  • Assigning to a variable
    I have a for each block where I want to assign the value in column 5 of the found row to the variable Serv. [CODE=vba] For Each ws In...
  • Way to verify information
    Hi All, I don't know what to call this formula, and therefore can't search. I have a spreadsheet with information I want to reference...
  • Active Cell Address – Inactive Sheet
    How to use VBA to get the cell address of the active cell in an inactive worksheet and then place that cell address in a location on the current...
Top