Controlling existing excel instrance or GetObject for VB.NET

L

Lee Moore

I would like to automate exporting an access query to excel from a vb.net
app, then using a worksheet saveas method to save it to another filename.
The problem I have
is, I am trying use access' runcommand method to export to excel, but it
leaves the excel app open and I cannot take control of it. The code is
below,
short and sweet.

Dim MSAccess As New Access.Application()

Dim MyWks As New Excel.Worksheet()

MSaccess.OpenCurrentDatabase("C:\Documents and Settings\lmoore\My
Documents\NewAdmits.mdb", False)

MSaccess.Application.Visible = True

MSaccess.DoCmd.OpenQuery("All")
MSaccess.DoCmd.RunCommand(Access.AcCommand.acCmdOutputToExcel)
Dim MSExcel As New Excel.Application()
MyWks = MSExcel.ActiveSheet.SaveAs("c:\all.xls") 'This fails. Not set to an
instance of an object
MSExcel.Quit()
MSaccess.Quit(Access.AcQuitOption.acQuitSaveNone)

I want to be able to assign the active worksheet to an object and then do a
saveas on that object. Any help would be appreciated.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top