This is the Add tag.

Excel icon

Add and return Excel.Worksheet references in VBA

The Workbooks.Open Method creates a new workbook, adds it to the Workbooks Collection, and returns a Workbook Object which can be set to an object reference. i.e.

Sub TestWorkbookAdd()

Dim wkbks As Excel.Workbooks
Dim wkbk As Excel.Workbook

Set wkbks = Excel.Workbooks
Set wkbk = wkbks.Add

End Sub

From Excel Help:

Creates a new workbook. The new workbook becomes the active workbook. Returns a Workbook object.

Continue Reading »

Outlook icon

Automatically attach a file to all outgoing messages

Someone on Outlook Code asked about automatically attaching a file to new messages. You could do this two ways:

  1. Create a new message programmatically and attach the file.
  2. Use the ItemSend Event to attach the file to all outgoing messages.

Here I'll demonstrate the first way, since I've already posted code for the second way. (see Attach files to an Outlook email using VBA)

Continue Reading »

Outlook iconVBA icon

Look for and create folders programmatically in Outlook

If you are writing VBA code for Outlook, you might have a need to check for an existing folder, and create it if it doesn't exist.

Here are two functions that can assist. I wrote one that checks for an existing folder, and returns TRUE if it exists. It assumes a specific folder hierarchy, so you'll need to adjust it if the folders you are working with are on a different level. Works in Outlook but can be adapted for Excel use as well.

Continue Reading »

Peltier Tech Charting Utilities for Excel