I am able to export MS Access 2010 tables to an Excel workbook with 
multiple tabs -- and it even overwrites the cells from the last time it ran 
-- but -- if there's less data than the previous run,  the left-over rows 
from the previous run screw up the data!  Obviously unacceptable.  So the 
solution is to run some code to clear out the old data before refreshing 
the workbook, tab by tab. 

Is there a VBA routine to do this?  I was able to find some code that kinda 
works (but it seems to ignore sheet1 as follows:

Function ClearSheets()
    Dim appXL As Object
    Dim wb As Object
    Dim WKS As Object
    Dim xlf As String
    Dim rs As DAO.Recordset
    Dim rng As Range
    xlf = "C:\TEST\MyWorkbook.xlsx" 'Full path to Excel file
    Set appXL = CreateObject("Excel.Application")
    Set wb = appXL.Workbooks.Open(xlf)
    Set WKS = wb.Sheets("Sheet1")
    Set rng = Range("A2:K" & Rows.Count)
    Set wb = Nothing
    Set rs = Nothing

End Function

It needs to work for multiple sheets, leaving the header rows and 
formatting alone -- and blank everything else. 

I appreciate the help! 

Thank you! 


Are you =EXP(E:RT) or =NOT(EXP(E:RT)) in Excel? And do you wanna be? It’s 
=TIME(2,DO:IT,N:OW) ! Join official Facebook page of this forum @ 


1) Use concise, accurate thread titles. Poor thread titles, like Please Help, 
Urgent, Need Help, Formula Problem, Code Problem, and Need Advice will not get 
quick attention or may not be answered.
2) Don't post a question in the thread of another member.
3) Don't post questions regarding breaking or bypassing any security measure.
4) Acknowledge the responses you receive, good or bad.
5) Jobs posting is not allowed.
6) Sharing copyrighted material and their links is not allowed.

NOTE  : Don't ever post confidential data in a workbook. Forum owners and 
members are not responsible for any loss.
You received this message because you are subscribed to the Google Groups "MS 
To unsubscribe from this group and stop receiving emails from it, send an email 
to excel-macros+unsubscr...@googlegroups.com.
To post to this group, send email to excel-macros@googlegroups.com.
Visit this group at https://groups.google.com/group/excel-macros.
For more options, visit https://groups.google.com/d/optout.

Reply via email to