- #Visual basic for applications excel tutorial how to#
- #Visual basic for applications excel tutorial code#
#Visual basic for applications excel tutorial code#
The last line of the code - ActiveProject.SetCustomUI (myNavBar) - assigns the new tab to the navigation bar. A button with the label HelloWorld is created, and the button's action is assigned the HelloWorld subroutine. As you read each line of the code, you'll notice the program is constructing an XML string that creates a tab called Utilities and a Group call MyTools.
#Visual basic for applications excel tutorial how to#
The Microsoft Project Developer Curriculum gets credit for providing an example on how to customize the Ribbon interface. Paste the following code into the subroutine: Dim myNavBar As String myNavBar = "" myNavBar = myNavBar + " " myNavBar = myNavBar + " " myNavBar = myNavBar + " " myNavBar = myNavBar + " " myNavBar = myNavBar + " " myNavBar = myNavBar + " " myNavBar = myNavBar + " " myNavBar = myNavBar + " " myNavBar = myNavBar + " " myNavBar = myNavBar + " " myNavBar = myNavBar + "" ActiveProject.SetCustomUI (myNavBar) Create a new subroutine called AddCustomNavigation.Ģ. Once we know our simple script is working, we need to create a navigation bar so we can call it from the Microsoft Project Ribbon interface ( Figure E).Ĭustom Utilities Navigation Step 6: Create a subroutine to build the custom menu bar in the Ribbon UI.ġ. The message box will display with the Microsoft Project file in the background. Step 5: Press F5 to Run the program (Figure D). Your one line subroutine should look like the code example below: MsgBox ("Hello World! This is my first VBA script in MS Project!") Type the following code in the subroutine section Select Insert | Procedure, enter HelloWorld into the Name field, and select the Sub Type radio button ( Figure C).Ĭlick OK, and the HelloWorld subroutine will appear. Step 4: Create the Hello World subroutine. This is the blank code screen where you'll paint your Hello World masterpiece. Visual Basic Editor (Click the image to enlarge.) Step 3: Double-click the ThisProject(HelloWord.mpp) file (Figure B). Step 2: Click the Developer tab and click the Visual Basic icon (Figure A). We will be using the schedule in future tutorials. Step 1: Open Microsoft Project.Ĭreate a sample schedule and save the file as HelloWorld.mpp. Let's start with the ever appropriate Hello World example. In my next several TechRepublic posts, I'll introduce you to some simple VBA examples that you can apply to your projects. For the project management community, there isn't a lot of material available that provides realistic examples on how to apply Visual Basic with your Microsoft Project schedule. Even though I don't write code for a living, I still like to apply Visual Basic to my projects.Ī quick Google search will reveal thousands of sites dedicated to VBA programming with Excel and Visual Basic. Eventually, I handed in my programming hat for a project management role and started managing products rather than creating them. Three years later, I was writing Visual Basic applications as an IT intern. Like most aspiring technologists, I found programming fun and, after learning I could get paid to work with computers, I jumped right in. I started fiddling with Visual Basic nearly 20 years ago in Mr.