Automatically run query in Excel and send email?

Associate
Joined
18 Oct 2002
Posts
2,055
Location
Southend-on-Sea
I have a spreadsheet that runs a query against a FoxPro database. At the moment, I have to open Excel, refresh the data and I then email the workbook to various recipients.

Does anyone know of a way I can automate this process? For example, at 4 p.m. each day the spreadsheet would automatically open, refresh the data and then email itself? Sounds like a bit of a tall order, but is this possible?

Thanks
 
Very possible. Which email client do you use? I created a spreadsheet which sends to lotus notes but not tried outlook (although its definitely possible)
 
I'm using Outlook. We have both 2003 and 2007, but a solution for just one of these will be good. How have you got it working with Lotus?
 
I can get the spreadsheet to open automatically using Windows task scheduler. I've taken a look and I'm pretty sure VBA can do the rest. Will give it a go this afternoon, but may be back with questions.

Cheers.
 
Set the vba up in the 'thisworkbook' section under

Private Sub Workbook_Open()

End Sub

and put Application.Quit at the end if you want to exit excel (if you have any other sheet open this would be a problem)

or you can close the workbook and specify if you want to save changes by

ActiveWorkbook.Close SaveChanges:=False
or
ActiveWorkbook.Close SaveChanges:=True
 
Last edited:
Back
Top Bottom