Access to Excel ( Overwrite current file )

sxs9999

New Member
Joined
Apr 26, 2004
Messages
44
Can any one tell me how to overwrite an excel spread sheet with out me have to click yes .


At the moment I run a crosstab and output this to excel, This is fine, But now I have to run this at 4 in the morning So i'm not here to ok the overwrite of the existing excel file. I've tried turning the warnings of as well as the confirmation but I still get this message asking if I want to overwrite the file...


Help Please
 

Excel Facts

What does custom number format of ;;; mean?
Three semi-colons will hide the value in the cell. Although most people use white font instead.
Rather than try to kill the warning, kill the file first! :)
Kill pathname

Peter
 
Upvote 0
Kill "C:\Temp\tempFile.xls"

Will delete the file from your harddrive. if you do this before running the code to write the file there will be no file to overwrite

Peter
 
Upvote 0
While personally, I've always done exactly what Bat17 suggested, delete the file first, I have noticed that Access2K during an export operation does seem to overwrite the file every time for me, no prompts. Sample functions included.

But, just because I've never had a problem doesn't mean it works 100% of the time. I remember testing this because I was uncertain whether the transferspreadsheet method would replace or append data to Excel.

Mike

Code:
Sub sendit()
Call ImportExport("acExport", "a_query_name", "pathtofile")

End Sub

Public Function ImportExport(ByVal Ltype As String, ByVal Tname As String, _
                                 ByVal TLoc As String) As Long
Dim intCnt As Integer
ErrorResume:
On Error GoTo Err_handler


Select Case Ltype:
    Case "acImport":  Ltype = 0
    Case "acExport":  Ltype = 1
    Case "acLink":    Ltype = 2
End Select
DoCmd.TransferSpreadsheet " " & Ltype, 8, Tname, TLoc, True, ""

Exit Function

Err_handler:

 Select Case Err.Number:
  Case 2391:
    'MsgBox Err.Number & " One or more fields in " & TLoc & " not in Database"
    'Debug.Print TLoc & " Has too many fields"
    Call RemoveXLSColumns(TLoc)
    intCnt = intCnt + 1
    If intCnt < 2 Then          ' Only attempt to remove columns once
      GoTo ErrorResume
    End If
  Case 3051:
    ' Somebody is in the table
  Case Else
    Debug.Print Err.Number & " " & Err.Description
 End Select
ImportExport = Err.Number
Err.Clear
End Function
 
Upvote 0

Forum statistics

Threads
1,221,808
Messages
6,162,097
Members
451,742
Latest member
JuanMark10

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top