Transfer spreadsheet

S

SageOne

Hi,

I currently have a transferspreadsheet macro that outputs the results of a
crosstab query to an excel file. It seems that I am getting a error "too many
fields defined" when the fields of the crosstab query increase from one run
of the macro to the next.

I need a code that will go out to an existing excel file, clear all the
cells of a specified worksheet or worksheets (erase all data, formats,
formulas with out deleting the tab or tab name), then transfer my crosstab
query to specified worksheet.

Another solution would be to delete all the worksheets in excel file but
this would break my vlookups in other worksheets so I just simply want to
clear the spread sheets instead of deleting them.

Here is my untested code so far but is there a better way?.......

Sub WorksheetClear()
Dim objXL As Object
Dim strFile As String

strFile = "\\cy.com\dfs\Data\SPAP-PRT_Analysis\Matt's
Team\Brashears\Project 0377 - Bucket db Reporting\DbReport.xls"

Set objXL = CreateObject("Excel.Application")
objXL.Workbooks.Open(strFile)

With objXL
.Sheets("Sheet1").Cells.Clear
.Sheets("Sheet2").Cells.Clear
.Sheets("Sheet3").Cells.Clear
End With

objXL.DisplayAlerts = False
objXL.Save
objXL.DisplayAlerts = True
objXL.Quit
Set objXL = Nothing
End Sub
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top