Open Excel File from Access

  • Thread starter Thread starter John
  • Start date Start date
J

John

The 2 things I can't figure out:
1) how to open an excel file from access

2) how to delete a worksheet in excel from access

If anyone could give me some ideas as to how to do either
of these I would greatly appreciate it.

Thanks,
John
 
-----Original Message-----
The 2 things I can't figure out:
1) how to open an excel file from access

2) how to delete a worksheet in excel from access

If anyone could give me some ideas as to how to do either
of these I would greatly appreciate it.

Thanks,
John
.
Hi John,

use tools|references to set a reference to the excel
object library.

dim xlApp as excel.application
dim xlWkb as excel.workbook
dim xlWsh as excel.worksheet

on error resume next
' reference open session of excel
set xlApp=getoject(,"excel.application")
if err.number<>0 then
' excel not already running
err.clear
on error goto 0
set xlApp=new excel.application
end if

set xlWkb=xlApp.Workbooks.open("path/name.xls")
set xlWsh=xlWkb.Worksheets("name")
xlWsh.delete

with xlWkb
..save
..close
end with

with xlApp
if not .usercontrol then
' opened excel using code
..quit
end if
end with

set xlWkb = nothing
set xlApp = nothing

You might like to post excel specific questions to the
excel programming usergroup.

Luck
Jonathan
 
Back
Top