Archive for the ‘Excel & Access Integration’ Category

Running an Excel Macro from Access (or Another Excel Workbook)

August 31st, 2010

One of the more common questions I get revolves around running an Excel macro from Access. That is, how do you fire an existing Excel macro from Access.

I'll share the code to do that in a moment.

I first want to point out that this code can also come in handy if you need to run an external Excel macro in another workbook. That is to say, while you are working in an Excel file, you can reach out and run a macro in another workbook.

 

OK. Here it is. Simply paste this code in a new module.

 

Sub RunExcelMacro()
Dim xl As Object

'Step 1:  Start Excel, then open the target workbook.
    Set xl = CreateObject("Excel.Application")
    xl.Workbooks.Open ("C:\Book1.xlsm")

'Step 2:  Make Excel visible
    xl.Visible = True

'Step 3:  Run the target macro
    xl.Run "MyMacro"

'Step 4:  Close and save the workbook, then close Excel
    xl.ActiveWorkbook.Close (True)
    xl.Quit

'Step 5:  Memory Clean up.
    Set xl = Nothing

End Sub

 

Some notes on the code:

Step 1: Create a new instance of Excel, open the target workbook; the workbook that contains the macro you need to run.

 

Step 2: Making Excel Visible. By default, Excel will open and run in the background (invisible to you). You can set the Visible property to TRUE if you need to see the workbook. If you don't want to see the Excel workbook while the macro is running, simply set the Visible property to FALSE.

 

Step 3: Run the target macro

 

Step 4: Close and save the target workbook. The True argument in xlwkbk.Close(True) indicates that you want the workbook saved after the macro has run. If you do not want to save the target workbook, change this argument to False. Also in Step 4, you quit the Excel application, effectively closing the instance of Excel.

 

Step 5: Release the objects assigned to your variables, reducing the chance of any problems caused by rogue objects that may remain open in memory.

Converting Text to Proper Case in Access

August 16th, 2010

Wendy writes to ask:

"In Excel, I can use the PROPER function to change my text to proper case. Why is there is no PROPER function in Access? "

Wendy has stumbled on one of the mysteries of life - there are many functions you use in Excel that are not found in Access. Well…it's not really a mystery. I actually have an idea why this may be.

  » More: Converting Text to Proper Case in Access

Can’t Export More than 65,000 Rows to Excel 2007?

April 22nd, 2010

Kusleika and I are at the Excel and Access Power User Workshop this week. Between you and me, he's not doing that well.

Anyway, one of our attendees asked why Access 2007 can't export more than 65,000 rows to Excel 2007. I replied with my usual professorial demeanor "What? You're on crack!"

This is when he demonstrated these steps:

» More: Can’t Export More than 65,000 Rows to Excel 2007?

The Case for Access

March 10th, 2010

Amazon says it's official. My new book will be out on April 5th.

This book is written for all you Excel users who know that expanding your skill-set to include Access can make you more productive. I guide you through analytical and reporting benefits of Access, and show you how you can integrate Excel and Access to make your life easier.

 

To celebrate this new arrival, I've decided to post Chapter 1 of this book as today's blog entry. Enjoy!

» More: The Case for Access

Avoiding Data Cut-Off in Excel

February 3rd, 2010

It's been a busy week and I've been working hard. I think I'll reward myself by writing a blog post for people I've never met. Here we go.

Let's talk about getting Access Memo Fields into Excel.

  » More: Avoiding Data Cut-Off in Excel

Clearing Access ImportError Tables

January 26th, 2010

If you move data from Excel to Access on a regular basis, you'll know that sometimes Access can't resolve the data being imported from Excel. In these cases Access automatically creates a new table called ImportErrors..
. » More: Clearing Access ImportError Tables

The Benefits of a Good Technical Editor

December 4th, 2009

I'm in the process of writing my Pulitzer worthy book "An Excel Analyst's guide to Access".  During the writing process, chapters get reviewed by a team of editors - one of which is a Technical Editor. 

The Technical Editor on this book is Dick Kusleika (Daily Dose of Excel).  Kusleika is one of the better technical editors I've worked with.  I think his accountant's detail-oriented brain lends itself nicely to tech editing. 

Quick  Joke:  Did you hear about extroverted accountant?  He looks down at your shoes. 

.

During his editing, Kusleika pointed out that that the serial dates in Access actually start at December 31, 1899 (not January 1, 1900 like in Excel). 

» More: The Benefits of a Good Technical Editor

Easily Move Access Query Results to Excel

November 19th, 2009

Just the other day, I saw someone run an Access Query in Office 2003. Then he selected Office Tools ->Analyze with Excel.  This essentially sends the results of the Access query to Excel.

.

This if fine and dandy, but there is a slightly easier way to get the results of an Access query to Excel.

. » More: Easily Move Access Query Results to Excel

Documenting Access Queries in Excel

October 26th, 2009

Clients usually have this pesky need to have everything documented. As a generally lazy person, this offends my lackadaisical attitude. Nevertheless, I typically oblige, given the fact that I want them to take over the work at some point.

 

Over the years, I've rolled my own documentation tools to help in this endeavor. Today, I want to share a small procedure I use to document Access queries in Excel.

  » More: Documenting Access Queries in Excel

Running an Access Parameter Query from Excel

October 19th, 2009

An Access parameter query is a kind of interactive query that prompts you for criteria before the query is run. Parameter queries are useful when you need to ask the query different questions using different criteria each time you run it.

Now we all know you can pull data from Access into Excel using MS Query. The problem is that MS Query doesn't let you pull in Parameter queries. There may be a technical reason for this, but I like to think it's just Microsoft's way of keeping things interesting. After all, technical roadblocks are the spice of life.
If you've had enough spice, I'll show you a VBA workaround that will enable you to run an Access parameter query from Excel.

  » More: Running an Access Parameter Query from Excel