Access controlling Excel

I have an Access app that dumps out excel data files, I need excel open for part 1 of the process but for the dump of the file I need to close excel.  I can not seem to figure out the Access VBA to determine if an Excel file is open and close the open excel file dump the excel files and then code to reopen that excel file for the file process
INSCNOCAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

danishaniCommented:
You might check below thread out:
http://www.cpearson.com/excel/IsFileOpen.aspx

I am sure there are plenty of more simular functions like this.

Hope this helps,
Daniel
0
danishaniCommented:
Check also this thread by Ron de Bruin, scroll down at part "Test if file is open":
http://www.rondebruin.nl/exist.htm
0
kmslogicCommented:
Const ERR_APP_NOTRUNNING As Long = 429
dim oExcel as Object

    Set oExcel = GetObject(, "Excel.Application")
    If Err = ERR_APP_NOTRUNNING Then
       Set oExcel = New Excel.Application
    End If

That will get you a handle to Excel (if it isn't running a new copy otherwise the running copy)
Then you can do stuff like


    Dim wb As Excel.Workbook
    For Each wb In oExcel.Workbooks
        wb.Close True
    Next
 
to close and save all open workbooks

to open a workbook

set wb = oExcel.Workbooks.Open MyFilename

to open a blank workbook

set wb = oExcel.Workbooks.Add

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Big Business Goals? Which KPIs Will Help You

The most successful MSPs rely on metrics – known as key performance indicators (KPIs) – for making informed decisions that help their businesses thrive, rather than just survive. This eBook provides an overview of the most important KPIs used by top MSPs.

INSCNOCAuthor Commented:
How can I close a particuliar Excel workbook, in case the user has multiple open.  I need only to close 1 workbook that is locking linked excel files that I need to update
0
kmslogicCommented:
oExcel.Workbooks("WorkbookName").close
0
INSCNOCAuthor Commented:
I get am error on

Dim wb As Excel.Workbook

User-defined type not defined
0
kmslogicCommented:
you have to have a reference to excel on your references (under tools in the vba editor) to do that, but if you do

dim wb as Object

that will work too.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft Access

From novice to tech pro — start learning today.