Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Delete Worksheets Prior To Access DoCmd.TransferSpreadsheet


Hi All,

I know this is an Excel group, but it's an Excel related problem. I a
using the DoCmd.TransferSpreadsheet command in Access (2000) t
transfer query results to an Excel workbook. It transfers fine, but th
problem I need to address is that I the transfer creates copies of th
worksheet if one already exists. (e.g., transfer "qxlsTest" creates
worksheet named "qxlsTest" if one does not exist, but create
"qxlsTest1" if one already does.) I need to delete or overwrite th
existing "qxlsTest" worksheet.

I can access the Excel workbook fine from Access. I can manipulat
worksheets (hide or change Cell values) fine, but I am not able t
delete worksheets. It seems to process the code, but the delete par
doesn't actually happen.

Here's (part of) the code I'm using:
(strFilename is the filename passed to this function)

Dim xlApp As Object
Dim wkb As Workbook
Dim wks As Worksheet

Set xlApp = CreateObject("Excel.Application")
Set wkb = xlApp.Workbooks.Add(strFilename)

xlApp.DisplayAlerts = False

' Iterate through all the worksheets in the workbook and delet
existing
' worksheets as needed.
For Each wks In wkb.Worksheets
' Check if the worksheet is an export from Access (prefix o
"qxls").
If Left(wks.Name, 4) = "qxls" Then
' Delete the current worksheet.
wks.Delete
End If
Next wks

After the code above, the DoCmd.TransferSpreadsheet occurs. Again, tha
part works alright. I'm just trying to delete or overwrite the existin
"qxls" worksheets.

Any help is greatly appreciated. I'm going nuts.

Thanks

--
wheatcracke
-----------------------------------------------------------------------
wheatcracker's Profile: http://www.excelforum.com/member.php...fo&userid=3205
View this thread: http://www.excelforum.com/showthread.php?threadid=51806

Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Access 2003: transferspreadsheet writes over existing spreadsheet ragtopcaddy via OfficeKB.com Excel Discussion (Misc queries) 0 April 21st 08 02:01 PM
how to format a Docmd to pull in an Access file in Text format Campbellj4 Excel Programming 0 November 2nd 05 04:22 PM
how to format a Docmd to pull in an Access file in Text format Campbellj4[_2_] Excel Programming 0 November 2nd 05 04:22 PM
Export to Range from Access with TransferSpreadsheet deko[_3_] Excel Programming 8 June 13th 05 01:54 AM
DoCmd.OpenReport problem onedaywhen Excel Programming 0 February 25th 04 09:52 AM


All times are GMT +1. The time now is 08:28 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"