• RyanDev.com

  • Quickly Teach Yourself To Program Visual Basic for Applications (VBA) - Lessons

6th June 2008

Quickly Teach Yourself To Program Visual Basic for Applications (VBA) - Lessons

Here are some quick and easy to use tutorials if you are interested in learning VBA.  Please let me know if there are other topics you would like me to cover.  There are 6 modules and each has a series of attachments to download the full documentation and code samples.  Below are summaries of what each module covers.


Module 1

Introduction

The purpose of this module is to familiarize you with the Visual Basic Editor environment and to introduce some coding techniques. By the end of this module you should be able to accomplish the following tasks:

  • Arrange and navigate the Visual Basic Editor
  • Write and edit macros
  • Write code to respond to events
  • Recognize and have a basic understanding of the Object Model

Attachments: Module 1.doc


Module 2

Introduction

The purpose of this module is to introduce automation of Microsoft Office products. By the end of this module you should be able to accomplish the following tasks:

  • Automate one Office product from within a different Office product
  • Understand how to reference the Object Model of different Office products
  • Use debugging techniques
  • Implement error handling

Attachments: Module 2.doc; DataFile.xls


Module 3

Introduction

The purpose of this module is to allow you to put in practice lessons from Modules 1 and 2. Each of the examples listed here come from real calls that I have had. By the end of this module you should be able to accomplish the following tasks:

  • Write custom functions in Microsoft Excel
  • Play a sound in Excel when a cell changes
  • Format cells in a Word table

Attachments: Module 3.doc; Count Criteria.xls


Module 4

Introduction

The purpose of this module is to introduce user forms that can be used in VBA. By the end of this module you should be able to accomplish the following tasks:

  • Create a user form in Excel.
  • Create a user from in Word to pull data from Access.

Attachments: Module 4.doc; Count Formulas.xls; Addresses.mdb


Module 5

Introduction

The purpose of this module is to introduce VBA programming with Microsoft Access. By the end of this module you should be able to accomplish the following tasks:

  • Create a new Microsoft Access database from within Excel.

Attachments: Module 5.doc; Addresses.mdb


Module 6

Introduction

The purpose of this module is to introduce VBA in Microsoft Outlook and Microsoft PowerPoint. By the end of this module you should be able to accomplish the following tasks:

  • Create a user form in Excel.
  • Create a user from in Word to pull data from Access.

Attachments: Module 6.doc; Addresses.mdb


posted in General Software Development, Microsoft Office | 1 Comment

16th February 2008

Date and Time Useful Functions for VB 6.0

Below is some sample code that I have used in the past that has some useful date and time functions.  The code was written in Visual Basic 6.0 but can easily be converted to .Net.


Attribute VB_Name = “TimeDateFunctions”
Public TheYear As Integer, TheMonth As Integer, TheDay As Integer

Public Function LastDayOfMonth(ByVal ADate As Date, PreviousMonth As Integer) As Integer ‘Previous month is an offset of the passed in date to return the last day in a different month

‘For example, if ADate is in February and PreviousMonth is 3, the last day of November will be given

‘This will not go back more than a year, previous month max is 12

Dim CurrentMonth As Integer, i As Integer

CurrentMonth = Month(ADate) - PreviousMonth

TheYear = Year(ADate)

If CurrentMonth <= 0 Then

CurrentMonth = 12 + CurrentMonth

TheYear = TheYear - 1

End If

TheMonth = CurrentMonth

Select Case CurrentMonth

Case 1, 3, 5, 7, 8, 10, 12

LastDayOfMonth = 31

Case 4, 6, 9, 11

LastDayOfMonth = 30

Case 2

LastDayOfMonth = 28

End Select

End Function


Public Function WeekDayName(ByVal WeekDayNum As Integer) As String

Select Case WeekDayNum

Case 1

WeekDayName = “Sunday”

Case 2

WeekDayName = “Monday”

Case 3

WeekDayName = “Tuesday”

Case 4

WeekDayName = “Wednesday”

Case 5

WeekDayName = “Thursday”

Case 6

WeekDayName = “Friday”

Case 7

WeekDayName = “Saturday”

Case Else

MsgBox “This function returns the name of the weekday that was passed in.” & _

“Valid parameter values are 1-7 corresponding to weekdays Sunday through Saturday.”

End Select

End Function


Download the code.

posted in General Software Development, Microsoft Office | 5 Comments

  • Links

  • Calendar

  • February 2012
    S M T W T F S
    « Jan    
     1234
    567891011
    12131415161718
    19202122232425
    26272829