Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations sizbut on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Open/Close Excel from Access 1

Status
Not open for further replies.

ajking

Technical User
Aug 13, 2002
229
I have a project where I take an excel form with three sheets and import the data into access. I have got it working using:
DoCmd.TransferSpreadsheet acImport, 8, "tbTechnical", "C:\CNS Excel Import\Email_CNS.xls", True, "ExportTechnical"
DoCmd.TransferSpreadsheet acImport, 8, "tbScan", "C:\CNS Excel Import\Email_CNS.xls", True, "ExportScan"
DoCmd.TransferSpreadsheet acImport, 8, "tbEmail", "C:\CNS Excel Import\Email_CNS.xls", True, "ExportEmail"

However the first step at the moment is to manually open the excel form so the transfer can take place and then close the excel form manually.
I have been trying to automate the process with little success. If anyone out there can help I would be most grateful as I am down to the last hundred hairs on my head ;-). TIA


'Life is what happens to you while you are busy making other plans' John W. Lennon 1940-1980
 
You can use automation to open and close a number of applications, including Excel, however, it should not be necessary to open Excel to use TransferSpreadsheet.
 
Hi Remou
If the excel form is not open I get an error message: "error 3274 - external table is not in the expected format"

'Life is what happens to you while you are busy making other plans' John W. Lennon 1940-1980
 
What version of Excel are you importing? I would imagine that it is the 8 (acSpreadsheetTypeExcel8 and 9) that is causing the problem.
 
Excel 2003 sp3. As I said, the import works fine and my access form populates correctly. I just want to automate the opening of the workbook and to close it after the import.

'Life is what happens to you while you are busy making other plans' John W. Lennon 1940-1980
 
Code:
Dim xl As Excel.Application

Set xl=CreateObject("Excel.Application")
xl.Workbooks.Open ("C:\docs\ltd.xls")
xl.Quit

I do not recall anyone, ever, having to open Excel to import a spreadsheet via Transferspreadsheet.
 
That code worked fine for the first time but when I tried it again a windows type popup appeared which had a title -" 'file now available' with the following text in the body:
'Email_CNS.xls' is now available for editing
Choose Read-Write to open it for editing"
I shut the database down and opened it again with the same result i.e. the popup 'pops up'. If I cancel the 'edit' choice, the excel file comes to the top and I have to close it manually

'Life is what happens to you while you are busy making other plans' John W. Lennon 1940-1980
 
Remou, you are a star! many thanks!

'Life is what happens to you while you are busy making other plans' John W. Lennon 1940-1980
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top