PC Review


Reply
Thread Tools Rate Thread

delete all in a csv file

 
 
alvin Kuiper
Guest
Posts: n/a
 
      28th Jan 2010
Is there away in access, to delete all in a csv file (excel) I only have one
sheet


 
Reply With Quote
 
 
 
 
Daniel Pineault
Guest
Posts: n/a
 
      28th Jan 2010
Here is a bit of code I put together rapidly.

Sub ClearXLSWrkSht(sXLSFile As String, sXLSWrkSht As String)
' sXLSFile :: Excel file with full path and extension
' sXLSWrkSht :: Worksheet name to be cleared

Dim xlApp As Object
Dim xlBook As Object
Dim xlSheet As Object
' For Early Binding you'd use these 3 lines instead of the 3 above
' Dim xlApp As Excel.Application
' Dim xlBook As Excel.Workbook
' Dim xlSheet As Excel.Worksheet
On Error GoTo Error_Handler

Set xlApp = New Excel.Application
xlApp.Visible = True 'Control whether or not Excel should be visible to
'the user or not.
Set xlBook = xlApp.Workbooks.Open(sXLSFile) 'Open the workbook
Set xlSheet = xlBook.Worksheets(sXLSWrkSht) 'Worksheet we are working with

xlSheet.Cells.Select
xlSheet.Cells.ClearContents 'Clear the contents

xlBook.Close True 'Close and save the workbook
xlApp.Quit 'Close the instance of Excel we create

Error_Handler_Exit:
On Error Resume Next
Set xlSheet = Nothing
Set xlBook = Nothing
Set xlApp = Nothing
Exit Sub

Error_Handler:
MsgBox "MS Access has generated the following error" & vbCrLf & vbCrLf &
"Error Number: " & _
Err.Number & vbCrLf & "Error Source: ClearXLSWrkSht" & vbCrLf & "Error
Description: " & _
Err.Description, vbCritical, "An Error has Occured!"
Resume Error_Handler_Exit
End Sub

It will clear the worksheet, preserving formatting. If you truly wish to
delete everything then you need to change the ' xlSheet.Cells.ClearContents
'Clear the contents' part of the code.
--
Hope this helps,

Daniel Pineault
http://www.cardaconsultants.com/
For Access Tips and Examples: http://www.devhut.net
Please rate this post using the vote buttons if it was helpful.



"alvin Kuiper" wrote:

> Is there away in access, to delete all in a csv file (excel) I only have one
> sheet
>
>

 
Reply With Quote
 
Daniel Pineault
Guest
Posts: n/a
 
      28th Jan 2010
Small correction for late binding use this line instead of the original line
in my sub

Set xlApp = CreateObject("Excel.Application")

--
Hope this helps,

Daniel Pineault
http://www.cardaconsultants.com/
For Access Tips and Examples: http://www.devhut.net
Please rate this post using the vote buttons if it was helpful.



"alvin Kuiper" wrote:

> Is there away in access, to delete all in a csv file (excel) I only have one
> sheet
>
>

 
Reply With Quote
 
Jack Leach
Guest
Posts: n/a
 
      28th Jan 2010
A csv file is just a text file... data values seperated by commas. Excel is
just one of a few ways to format the data to a meaningful view. Is there
some reason that this needs to be done in excel? Why not just erase the csv
file?

--
Jack Leach
www.tristatemachine.com

"I haven''t failed, I''ve found ten thousand ways that don''t work."
-Thomas Edison (1847-1931)



"alvin Kuiper" wrote:

> Is there away in access, to delete all in a csv file (excel) I only have one
> sheet
>
>

 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
can i delete an email and skip the delete file as a single step Hugh Microsoft Outlook Discussion 1 8th Apr 2010 01:07 PM
Delete only unread messages in my delete file =?Utf-8?B?U3Vl?= Microsoft Outlook Discussion 3 7th Jul 2005 11:21 AM
Difference between Delete Subfolders and File and Delete =?Utf-8?B?Um9i?= Microsoft Windows 2000 File System 0 29th Jun 2005 03:31 PM
Re: Macro to delete sheets and saves remaining file does not properly delete module gazornenplat Microsoft Excel Programming 0 22nd Jun 2005 01:12 AM
Macro to delete sheets and saves remaining file does not properly delete module pherrero Microsoft Excel Programming 7 21st Jun 2005 05:16 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 06:53 PM.