Microsoft Excel Visual Basic Code Samples

  1. Microsoft Visual Basic Excel Error
  2. Visual Basic Codes For Excel
  3. Simple Visual Basic Examples
  4. Microsoft Excel Visual Basic Code Samples Printable

VB.NET Excel examples

Create a Macro: With Excel VBA you can automate tasks in Excel by writing so called macros. The Excel VB.NET add-in shows how to build a context-dependent custom task pane. The plug-in shows a task pane when cell A1 contains any value. Download plug-in. How to re-size an Excel task pane in VB.NET. This Visual Basic.NET example shows how you can resize your custom form using Advanced Task Panes for Excel 2019 - 2000. Microsoft Excel, being a spreadsheet application, automatically brings structure to your thinking. You can build models to help you think through just about anything. You can organize your data and create lists of any imaginable type. In fact, most apps in the mobile app stores these days can easily be replaced by Excel files.

On this page you will find a set of HowTo samples that can help you to get started with add-in development for Excel 2019, 2016, 2013, 2010 and lower:

And here are a few more VB.NET examples for other applications of the Microsoft Office 2019 - 2000 suite:

Excel extensions: COM add-in, RTD server

How to develop a COM add-in for Microsoft Office (Excel, Word and PowerPoint)

This sample shared COM add-in for Excel, Word and PowerPoint shows how you can use Add-in Express for Office and .net to add custom command bars and command bar controls, place new controls onto Office Ribbon tabs, create custom task panes, handle application-level events and more.
Download COM addin

How to customize Microsoft Excel ribbon and toolbar

See how to create custom ribbons and toolbars for Excel and how to integrate with an existing Excel tab.
Download add-in

How to customize Excel main menu, context menus and Backstage view

VB.NET sample shows how to create a custom context menu for Excel 2019, 2016, 2013, 2010, 2007 and lower; how to add your own Backstage view item and how to customize the main menu in Excel 2003 - 2000.
Download sample

How to build your first Excel RTD server in VB.NET

See how to build an RTD server step-by-step in the Developer's Guide. The RTD server project is written in Visual Basic .NET. See also a video showing how to create an RTD server.
Download RTD server

Working with Excel Object model

How to handle the WorkbookBeforeSave event

How to create a custom event when Excel calculation mode changes

This VB.NET Excel addin example provides a solution for missing event that should occur then the user changes the calculation mode.
Download addin

How to find the last used cell (row or column) in Excel

This Visual Basic sample explains some reliable methods for finding the last used cell in an Excel worksheet or a range.
Download Find Last Cell add-in

Samples

How to populate Excel workbooks and ranges with arrays

VB.NET code example shows how to use arrays to populate Excel with data; how to fill array with a query or range and insert into a worksheet, and more.
Download Populate with Arrays add-in

How to work with Excel tables & ranges using VB.NET

This sample Excel addin demonstrates how work with tables and ranges: create a new table or a range, insert a column or a row, sort, filter and more.
Download Excel Tables and Ranges add-in

How to work with Excel pivot tables

VB.NET code example shows how to automate pivot tables in Excel: create a PivotTable, add calculated fields, display or hide a field; delete, refresh or clear a pivot table; create a pivot chart and more.
Download Excel PivotTables Add-in

Advanced Excel Task Panes

How to show and hide Excel Task Panes programmatically

This Visual Basic .NET Excel sample demonstrates how to set the visibility of an advanced task pane to make it show up from the command bar.
Download VB.NET sample

How to switch between several task panes programmatically

This addin shows how you can use several custom task panes in one position and switch between them programmatically.
Download example

How to show an advanced Excel task pane dynamically

The Excel VB.NET add-in shows how to build a context-dependent custom task pane. The plug-in shows a task pane when cell A1 contains any value.
Download plug-in

How to re-size an Excel task pane in VB.NET

This Visual Basic .NET example shows how you can resize your custom form using Advanced Task Panes for Excel 2019 - 2000. To change the form size programmatically, you set the splitter to none. Otherwise, only the user can resize the task pane using the splitter.
Download sample plugin

User-defined functions

How to develop Excel Automation add-in

See how to create Excel Automation add-ins step-by-step in the Developer's Guide. The sample is written in VB.NET.
Download Automation add-in

How to develop XLL add-in

This sample project demonstrates how you can build an XLL addin in Visual Studio. You can find a detail description of this example in the Developer's Guide: How to create an XLL add-in.
Download XLL addin

Note. You can find plenty more HowTo examples on our technical blog. Be sure to check it out, we add new HowTo samples every week.

Milestones Professional Automation: Microsoft Excel VBA Examples

Warning: The information on these pages should only be used by software developers who are familiar with a Windows programming environment. KIDASA does not take responsibility for any damage caused to your information or computer due to programming errors.

Play xbox on macbook. Excel VBA Example #1

Here’s a simple example of how Milestones Professional’s OLE Automation can be used to reformat a Microsoft Project schedule for printing on a single page on a large format plotter.

The Microsoft Excel spreadsheet:

The Milestones schedule:

If you would like to try this example, do this:

  1. Download the MilestonesOLEExcelExample1.zip file
  2. “Unzip” the file to a folder on your computer.
  3. Copy the Template (ExcelTemplate1.mtp) to your Milestones Professional personal templates folder.
  4. Start Excel and open the ExcelExample.xls file.
  5. In Excel, choose Macro on the Tools menu, then choose Macros.
  6. Click to select the “CreateOutlinedSchedule” macro.
  7. Click the run button.

(This download is recommended for those familiar with Visual Basic and Microsoft Excel).

Excel VBA Example #2

Here is a more advanced example of how you might use Milestones Professional’s OLE Automation interface with Excel.

Produces a schedule for each sheet in the Excel Workbook.Each sheet represents a condominium building project.

The Excel worksheet (shown below the schedule), includes:

  • contractor name
  • the type of contract (hook up gas, cabinets, …)
  • Contract total $
  • $ paid (used) to date
  • % of work complete
  • The program calculates the % of money remaining and compares it to the %of work remaining.
  • The % of work remaining and % of money remaining are displayed as a pie symbol.
  • The “performance indicator” column gives a quick way of telling whether the subcontract is in trouble (red), doing ok (yellow) or doing very well (green). The colors are based on how the % of work remaining compares to the % of money remaining.

Partition wizard mac. The schedule

To try this example

If you would like to try this example, click here to download a zip file which contains:

MilestonesOLEExcelExample2.xls – The Excel spreadsheet with data and program
ExcelTemplate2.mtp – The Milestones Professional template used by the program

(This download is recommended for those familiar with Visual Basic and Microsoft Excel).

Excel VBA Example #3

Here’s a simple example of how you might use Milestones Professional’s OLE Automation to take information from an Excel spreadsheet and generate a schedule with a DataGraph.

The Spreadsheet (partial)

The Milestones Professional Schedule:

To try this example:

  1. Download the MilestonesOLEExcelExample3.zip file
  2. “Unzip” the file to a folder on your computer.
  3. Copy the Template (ExcelTemplate3.mtp) to your Milestones Professional Personal template folder.
  4. Start Excel and open the ExcelExample.xls file.
  5. In Excel, choose Macro on the Tools menu, then choose Macros.
  6. Click to select the “CreateOutlinedSchedule” macro.
  7. Click the run button.

(This download is recommended for those familiar with Visual Basic and Microsoft Excel).

Note: The DataGraph and ValueSet are defined in the template and are automatically generated using the numbers in the “Mail Qty” Column. The numbers are spread over the duration of the task’s time frame.

Excel VBA Example #4

This example creates a spreadsheet from a Milestones Professional schedule.

The Excel Visual Basic Program:

Here’s the Visual Basic Program that generates a spreadsheet from an existing Milestones Professional schedule. This is a simple example which you may use as a starting point for building your own program.

To try this example:

If you would like to try this example, do this:

  1. Download the MilestonesOLEExcelExample4.zip file
  2. “Unzip” the file to a folder on your computer.
  3. Start Excel and open the MilestonesOLEExcelExample4.xls file.
  4. In Excel, choose Macro on the Tools menu, then choose Macros.
  5. Click to select the “CreateSpreadsheet” macro.
  6. Click the run button.
  7. When prompted, enter the name of an existing Milestones Professional schedule.

Microsoft Visual Basic Excel Error

(This download is recommended for those familiar with Visual Basic and Microsoft Excel).

Excel VBA Example #5

Visual Basic Codes For Excel

This example uses OLE Automation to generate schedule for a specific resource, taken from an Excel spreadsheet:

  • User runs the VBA macro “MakeMiles”
  • A form is populated with available Resource Names from the spreadsheet.
  • User selects the desired resource name
  • “MakeMiles” creates a Milestones schedule of that resource’s tasks.

The Milestones Professional Schedule:

To try this example:

Simple Visual Basic Examples

If you would like to try this example, do this:

  1. Download the MilestonesOLEExcelExample5.zip file
  2. “Unzip” the file to a folder on your computer.
  3. Start Excel and open the MilestonesOLEExcelExample5.xls file.
  4. In Excel, choose Macro on the Tools menu, then choose Macros.
  5. Click to select the “MakeMiles” macro.
  6. Click the run button.

Microsoft Excel Visual Basic Code Samples Printable

(This download is recommended for those familiar with Visual Basic and Microsoft Excel).