Transcript for:
Visual Basic Editor Navigation Tutorial

welcome to this yl tutorial in this video we're going to teach you about working with the Visual Basic editor application with an name to writing some Excel VBA code in this video we're not going to write any code itself what we are going to do is show you how you can set up and work with the Visual Basic editor so we'll start by showing you how you can access the VB editor from whichever version of excel you happen to be working in we'll talk to you about how you can switch between the uh the VB editor and Excel itself with some nice quick keyboard shortcuts and we'll also give you a quick Whirlwind tour of the VB screen and explain what the main windows in the VB editor application are for once we've covered that we'll move on to show you how you work with modules which are the places where you're going to write your code so I'll talk you about how you can create and remove modules how you can switch between the various ones you've created how you can rename them and finally how you set up the fonts and colors that you're going to use while you're actually programming so let's get started before you can start writing VBA code you first of all need to open up the Visual Basic editor application and the way that you do that depends on which version of excel you happen to be using if you're in Excel 2003 you can quite simply head to the tools menu find the macro option in there and then click the Visual Basic editor option there too you'll probably find that it gets a bit annoying having to go through this menu every time you want to get to that option so alternatively you could also display the Visual Basic toolbar in Excel to do that you need to rightclick somewhere at the top of the screen where all the existing toolbars are choose Visual Basic and then I'm going to drag this and Nest it up at the top of the screen like all the other toolbars you should find on there that there's a symbol button you can click on to take you to the Visual Basic editor and there it is to get into the VB editor in Excel 2007 I first of all need to display the developer tab in the ribbon at the top of the screen and to do that I need to go to the office button at the top left hand corner choose Excel options and then on the popular page of the dialog box that I'm looking at find the checkbox which says show developer tab in the ribbon check it and then click okay you should find that there's a new tab in the ribbon now called developer and if you go to that one the very first button on there Visual Basic clicking it will take you to the VB editor yet again if you're in Excel 2010 or 2013 you also need to display the developer tab in the ribbon but the way you do it in these two versions of excel is slightly different to 2017 what you need to do is right click on any existing ribbon tab choose customize the ribbon and then on the dial box which appears find the unchecked box next to the word developer check it and then click okay once again you'll find the developer tab appears in the ribbon and if you select it you'll be able to click on the first button there visual basic to take you once again into the Visual Basic editor whichever version of excel you happen to be using when you want to switch back into Excel itself you can simply click on the first button on the VP editor toolbar it looks like a little Excel icon if you click on that it take you straight back to excel you can also just use the taskbar although you can't see it on my screen if I hover my mouse at the bottom of the screen it will pop up with the two icons related to the two applications so you can simply click on on either of those two to switch you between the two applications you might also have noticed while I've been recording this little bit of the video that when you hover the mouse over certain icons it displays a tool tip so you'll see the alt and f11 keyboard shortcut will allow you to switch backwards and forwards between the two applications if you hold on the ALT key and then press f11 you have hours of fun switching between the two applications so on to the VB editor itself how does the application work well it's a fairly standard looking Microsoft Office application although it uses the Old School menus and toolbar system you should be reasonably familiar with with being able to click on menus to choose options and cck on buttons on toolbars to make things happen one thing that is quite different about the VP editor compared to other Microsoft Office applications is the number of Windows that it uses little individual panels which display different bits of information now these two windows that you can see at the moment the project Explorer and the property window are the two that were always displayed by default but there are many more available and you can open and close them as and when you want to if you close down a window or two you'll always be able to find them again from The View menu so if I choose the view menu I can find my project Explorer which I've just closed down and also my properties window there will always be a keyboard shortcut available to open these as well so F4 for properties control and R for the project Explorer it's also possible to move the windows around from their current positions and you can do that by simply clicking and dragging on the title bar of a window so if I click and drag on the properties window you'll see that I get a thin outline border which changes to a thick outline border as I undock it from its previous position when I release the mouse I've now got a free floating window which sits can can be positioned anywhere on the screen you can also dock it to different positions so if I start dragging it across to the right and watch for when they're thick gray border changes to a thin gray border instead I'll find that I can release the mouse button now and it will sit in and Nest itself to another part of the screen so you can feel free to play around with this docking it to various regions until you find a nice layout for the way you want to work it can be a little bit tricky getting that back into its original position actually so if I undock it from the bottom of the screen where it currently is then start to drag it towards the left hand Edge where I think it should be when it changes from thick to thin if I release the mouse button by default it doesn't actually go back into its original position so the the way you where you release the mouse button is very very important here I've found massive difficulties doing this in the past so for this one let's see if I can get it back in the right position if I drag it down towards the bottom of that left hand panel there we go it goes from thick to thin there and if I release the mouse button I just need to change the size and the height of that window now by clicking and dragging in between them there we go back to roughly its original position if we want to write some VBA code we need somewhere to write it and the best place for that in the Visual Basic editor is in something called a module you can create modules in a couple of different ways one method uses the project Explorer window at the top left hand corner of the screen if you rightclick with the Mouse anywhere inside the project you're working on you can choose to insert a module when you do so your module will appear as a separate floating window somewhere in the middle of the screen and your project Explorer will create a modules folder with a little icon representing the module you've just created another way to create a module is to use the insert menu so if you choose insert module that will create a module for you as well so you get another icon representing that module and another separate floating window in the middle of the screen you can close these windows down happily by clicking the process in this top right hand corner and you can double click on the module to redisplay it you can also maximize a module by um clicking the the middle of the three buttons in the top right hand corner of its window that will give you a bit more space on screen to write your code if you do that for all your modules when you want to switch between them you need to double click to switch between them so you can see the little title bar at the top of the window here shows you which module you're currently looking at Double clicking we'll switch between the different modules closing the modules down then is a case of clicking the bottom of sorry the lower of the two crosses in the top right hand corner of the screen and that will close down the individual module Windows rather than the entire VB editor you can also choose to remove a module or delete it and you can do that by right clicking on a module choose the remove option and then be careful about which button you click on the message which appears the Temptation here is always to click yes whenever you see one these sorts of messages from Microsoft but um the button you actually want to click here is no you don't want to export the module before you remove it unless you actually do want to do that we don't want to export our module so if you click no that will delete the module one by one without exporting it another useful thing to be able to do with a module is to rename it to describe what's going to be contained within it so if I want to do that I need to create another new module first so I'm going to write right click in my project Explorer and choose insert module and then I need to rename it to give it a sensible label Now intuitively using Microsoft products you'll want to be able to right click on that until you rename but you'll be quite disappointed to find that it that the rename option isn't there so you can't rename a module by right clicking on it nor can you rename a module by clicking once on its name pausing and then clicking again and waiting for the the text cursor to appear um the only way you can rename a module is by selecting it and then using the properties window at the bottom of the screen so the properties window displays the properties of whatever object you select if I select the this workbook object I get another longer list of properties if I select the project itself I get a simple name property so I can rename my project as well as the individual modules within it but all I want to do here is rename the module I'm going to select that um name I'm going to call it something like the basics because that's what we're going to display now the names of modules follow some conventions some rules you can't use spaces in the names of your modules and many punctuation characters are disallowed as well so if I try to include a space between the word the and Basics and if I try to hit enter I'll fin I get an um error message telling me that's not a legal object name so you'll find some people like me who are quite lazy tend to just to miss out the spaces all together you'll also find another convention is to use the underscore character in place of a space so that is another valid object name the basics now we're nearly ready to start finally writing some code but before we begin there's one last thing that I think is worthwhile setting up and that's the font that you're going to use while you're programming so to modify that head to the tools menu at the top of the screen choose the options of option from within there and then on the dialog box which appears head to the editor format tab now this page of the dialog box gives you all the settings require to modify the fonts you're going to use when you're programming and the sample box at the bottom right hand corner shows you what it will currently look like so if you don't like the standard setup you can change things like the font that you're using if you don't like cier new Western you can click on the drop down arrow and choose any other font install on your computer so you can use Times New Roman aial Etc you can even if you really must choose comic Sands nms to program it I don't even know why that's a choice to be briefly honest but you could program in comic Sands if you must I'm not going to I'm going to revert back to ker new Western which I think is a much more sensible Choice one thing that will help me um with with the videos is actually to increase the font size as well so I'm going to increase up to 14 which should make it a bit easier for you guys to read what I'm writing on screen and then one last thing that's worth mentioning here as well is the ability to change the color of different types of text so the Visual Basic editor represents different types of code in different colors you can see the list on the left hand side of different types of text you might see so for example if I click on syntax error text you might be able to see that the sample has changed to be a bright red in color so whenever you make a syntax error when you're programming that'll be immediately highlighted in red text to pick another example there's comment text as well if I select comment text that turns a dark shade of green now this sounds like a very good idea representing one type of text in green one in red unless you happen to be red green color blind in which case that choice is particularly useless so you can actually choose and Define your own colors for different types of text you can change the foreground color with a foreground option I don't know why I've chosen red again that was the one I'm trying to avoid sorry if I go for yellow perhaps and the background color you can change as well so I go for maybe a a blue background color that should make different types of text stand out to make it easy for you to read I'm just going to revert to also for both of these for the time being and then click okay and we're finally ready I think to start writing some code if you've enjoyed this training video you can find many more online training resources at www.y l.c.