Plan your holiday meals in Excel

christmas tree

Debra Dalgleish has a couple of meal planners in Excel which you can download. We're going to enhance them with some API goodness!

There are two very useful spreadsheets you can download from her site, if you're planning to host a holiday party.

Visit those articles for screenshots and download links. What we're going to do is make them even better by adding code that looks up recipes via web API, and returns the result to Excel. Now, when you add ingredients to the cooking list, you can look up recipes for cooking suggestions!

We'll use the same technique as found in the YQL post: the XML import feature of Excel 2003 and greater.

The Method

The entire code to call the API and return the response to Excel is as follows:

Sub GetRecipes()
  On Error GoTo ErrorHandler

  Const RangeToImport As String = "$A$10"

  ' delete existing xml map (if any)
  If ActiveWorkbook.XmlMaps.Count > 0 Then
    ActiveWorkbook.XmlMaps.Item(1).Delete
  End If

  ' clear out range to prep for new import
  Range(RangeToImport).CurrentRegion.Cells.Clear

  ' import web XML to destination range
  ActiveWorkbook.XmlImport URL:= _
                           "http://www.recipepuppy.com/api/?q=" & _
    URLEncode(Range("B1").Value) & "&format=xml", ImportMap:=Nothing, _
                           overwrite:=True, Destination:=Range(RangeToImport)

ProgramExit:
  Exit Sub
ErrorHandler:
  MsgBox Err.Number & " - " & Err.Description
  Resume ProgramExit
End Sub

As usual, download the URLEncode function to make this work.

You might notice in Debra's workbooks that the DinnerPlan worksheet has dinner items listed multiple times. In order to create a unique list for the recipe lookup dropdown list, I used the code found at Extracting a Unique List.

The API

The API is provided by Recipe Puppy.

Download the workbooks

Download updated Dinner Planner for Excel 2003
Download updated Dinner Planner for Excel 2007
Download updated Holiday Planner for Excel 2003
Download updated Holiday Planner for Excel 2007

Further Reading

Excel Event Planner and RSVP Manager

About JP

I'm just an average guy who writes VBA code for a living. This is my personal blog. Excel and Outlook are my thing, with a sprinkle of Access and Word here and there. Follow this space to learn more about VBA. Keep Reading »

Share This Article:

Share and bookmark this articledelicious buttonfacebook buttonlinkedin buttonstumbleupon buttontwitter button

Related Articles:



comment bubble 2 Comments on Plan your holiday meals in Excel:

  1. Debra Dalgleish writes:

    Thanks JP! That's a great addition to the dinner planners, and might inspire me to try a few new recipes during the holidays.

    • JP writes:

      You're welcome, and I just found another API that returns ingredient lists and recipes, instead of just URLs. I'll try to integrate it into the workbooks sometime soon.

This article is closed to new comments. Why?
Random Data Generator