• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 229
  • Last Modified:

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
0
INSCNOC
Asked:
INSCNOC
  • 3
  • 2
  • 2
1 Solution
 
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
Cloud Class® Course: Microsoft Office 2010

This course will introduce you to the interfaces and features of Microsoft Office 2010 Word, Excel, PowerPoint, Outlook, and Access. You will learn about the features that are shared between all products in the Office suite, as well as the new features that are product specific.

 
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
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

  • 3
  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now