Jump to content
Welcome Guest!

Join us now to get access to all our features. Once registered and logged in, you will be able to create topics, post replies to existing threads, give reputation to your fellow members, get your own private messenger, and so, so much more. It's also quick and totally free, so what are you waiting for?

Sign in to follow this  
Caleeco

[Course] Take me to the VBA! (Visual Basic Editor)

Recommended Posts

Caleeco    8

2. Take Me to the VBA! (Visual Basic Editor)

 

2.1 Introduction 

If you've used Microsoft Excel, you're probably familiar with it's interface (Menu at the top, grid at the bottom, scrolly thing on the side). "But where do my Macros go?" I hear you ask....That's a good question, and one you'll know the answer to by the end of this post.

 

2.2 The Visual Basic Editor (VBE) & How do I get there?

The Visual Basic Editor is an environment where you can compile & edit your visual basic code (the clues in the name right?). There are many ways to skin a cat (please don't try though! it's cruel :wtf: ), and in the same respect there is more than 1 way to get to the VBE. My preference is to use the keyboard shortcut ALT+F11. However, depending on which version of Excel you have installed you may need to enable the Developer Ribbon (Google it).

 

Once you have accessed the VBE, you will be presented with a screen like the one below:

35mr140.jpg

 

You'll notice the file tree structure in the top left (known as the Project Window). We will use this organise our Macros, similar to how you use Windows File Explorer. By default we have 3 sheets (associated with the 3 sheets within the excel workbook) & the excel workbook object. The layout of this structure, and how we might want to use it in different ways will be covered in a later course module. But for now lets just understand the basics. 

 

The bottom left hand corner, is your properties window. This lists the properties of the active coding window, for the most part, you wont have to interact much with it (it tends to do its own thing) So let's leave it alone... we do not want to anger the property window! 

 

The right hand side is where the 'magic' happens (Yes... VBA is magical, stop laughing!!). This is the coding window (you may need to double click 'Sheet1' in the project window to see it), and will be where we type all of our code to do fancy things in our spreadsheets. 

 

2.3 Can I start writing VBA Code now? 

*Sigh* there are a few more things we really need to learn before we start writing our own code... but seeing as we've found the Visual Basic Editor (World's Worst Hide & Seek Contestant) using out handy keyboard shortcut (ALT+F11).... why dont we try writing our first program!

:D

 

Now in the programming community, it is convention for your first code to be a 'HELLO WORLD' program (basically just a pop-up box that says 'Hello World!'). But that's boring... and conventions are not legally enforceable, So try copy/pasting the code below into your Coding window instead and then hit F5 on your keyboard (shortcut to run your program)

 

Sub ExcelWTF_VBA_Course()

    MsgBox "Look at me! I'm a goddamn programmer! Release the Kraken!!!"
    
End Sub

Woah! Woah! Woah! Keep your Kraken where it is... nobody want to see that 

:lol: Don't worry if you don't understand the code or the syntax we just used, these will be covered in detail in later tutorials part of this VBA course.

 

But that's all there is to the VBE:

  • We know where it hides (ALT+F11)
  • We know where to put our code (Coding Window)
  • We know how to run our code (F5)

 

The next tutorial will delve into how we start coding! So sit tight, more tutorials are coming soon....

 

Quote of the Day: "If every day is a gift... can someone tell me where I can return Mondays?!?!"

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×