Can anyone guide me to a solution for this issue? I need to export data to
excel and I need to inform the user about the possibilty that they have the
workbook they want to write to opened in Excel.
A way to find out if a certain worksheet exists in that excel workbook is
also welcome as the oCmd.TransferSpreadsheet overwrites existing sheets.
Thx a lot!
>.
>
Not an option I'm afraid, this is how the client wants it. All done from
Access ... an Excel file is one of the options, not the only one (csv, dbf
etc ...)
Thx for your taughts
<anon...@discussions.microsoft.com> wrote in message
news:0e8601c48ba7$f64ff110$a301...@phx.gbl...
You to find out whether a certain worksheet exists in a file, you will have
to open the file using automation, and if the file is already open then that
attempt will fail, so you can kill two birds with one stone:
Dim oXL As Excel.Application
Dim oWkb As Excel.Workbook
Dim oSht As Excel.Worksheet
On Error GoTo ProcErr
Set oXL = CreateObject("Excel.Application")
Set oWkb = oXL.Workbooks.Open(strExcelFile)
' this will fail if someone had the file open - trap the error
Set oSht = oWkb.Worksheets(strSheetName)
' this will fail if the sheet does not exist - trap the error
MsgBox "WorkSheet already exists"
--
Good Luck!
Graham Mandeno [Access MVP]
Auckland, New Zealand
<worki...@news.postalias> wrote in message
news:%233R0JS6...@TK2MSFTNGP09.phx.gbl...
> You to find out whether a certain worksheet exists in a file, you will have
> to open the file using automation
Have to? There are various ways of doing so using VBA and I've found
the following to be very fast:
http://support.microsoft.com/default.aspx?scid=kb;EN-US;q209189
In comparison, automating Excel and opening the workbook in its native
app is very slow.
Jamie.
--
I have some issues with the code ...
See comments in line ...
"Graham Mandeno" <Graham....@nomail.please> wrote in message
news:ee1vZO7i...@TK2MSFTNGP15.phx.gbl...
> Hi Workinghard :-)
>
> You to find out whether a certain worksheet exists in a file, you will
> have
> to open the file using automation, and if the file is already open then
> that
> attempt will fail, so you can kill two birds with one stone:
>
> Dim oXL As Excel.Application
> Dim oWkb As Excel.Workbook
> Dim oSht As Excel.Worksheet
> On Error GoTo ProcErr
> Set oXL = CreateObject("Excel.Application")
> Set oWkb = oXL.Workbooks.Open(strExcelFile)
This line does not generate an error ... even if the file is open
... it is a test to see if the workbook exists, not if it is open as far as
I can find.
> ' this will fail if someone had the file open - trap the error
> Set oSht = oWkb.Worksheets(strSheetName)
> ' this will fail if the sheet does not exist - trap the error
> MsgBox "WorkSheet already exists"
Second problem: Set oXL.Nothing does not shut down EXCEL !
I found the quit method on the excel app object!
I'm using your code to check for a worksheet exists and the code in the MS
knowledge article for cheking if the workbook is opend.
Thx to both you!
<worki...@news.postalias> wrote in message
news:%23P%23xBnFj...@TK2MSFTNGP10.phx.gbl...