AVOID THE ?DO YOU WANTO TO REPLACE IT?? QUESTION

AVOID THE REPLACE FILE QUESTION

I`ve export the data of a data grid to an excel file, but everytime that i run the app the question doyo wan to replace it (the file shows, con anyone help me

Sub entrar()

'Start a new workbook in Excel.

oExcel = CreateObject("Excel.Application")

oBook = oExcel.Workbooks.Add

'Create an array with 4 columns and 100 rows.

Dim DataArray(99, 3) As Object

For r = 0 To 99

DataArray(r, 0) = "ID" & Format(r + 1, "000")

DataArray(r, 1) = blu(r)

DataArray(r, 2) = bla(r)

DataArray(r, 3) = fecha.Text

Next

'Add headers to the worksheet on row 1.

oSheet = oBook.Worksheets(1)

oSheet.Range("A1").Value = "Id"

oSheet.Range("B1").Value = "Solucitud"

oSheet.Range("C1").Value = "Usuario"

oSheet.range("D1").value = "Fecha"

'Transfer the array to the worksheet starting at cell A2.

oSheet.Range("A2").Resize(100, 4).Value = DataArray

'Save the Workbook and quit Excel. ( here 's where i have the issue, i want to save but no having the replace question )))

oBook.SaveAs("C:\Documents and Settings\OPERADOR\Mis documentos\Nuevo" & "Book1.xls")

oSheet = Nothing

oBook = Nothing

oExcel.Quit()

oExcel = Nothing

GC.Collect()

Thanks





Answer this question

AVOID THE ?DO YOU WANTO TO REPLACE IT?? QUESTION

  • Michael Hansen


    oExcel.DisplayAlerts = False

    oBook.SaveAs("C:\Documents and Settings\OPERADOR\Mis documentos\Nuevo" & "Book1.xls")

    oExcel.DisplayAlerts = True



  • Lisber


    Set the DisplayAlerts property of the Excel Application object to False, perform the SaveAs and then set it back to True.

  • uzs1

    You can also try to delete the file before you save it.

    If System.IO.File.Exists("C:\Documents and Settings\OPERADOR\Mis documentos\Nuevo" & "Book1.xls") Then System.IO.File.Delete("C:\Documents and Settings\OPERADOR\Mis documentos\Nuevo" & "Book1.xls")

  • WQP

    Do you have an example of that

    cause help on linedoesn`y know anything about it

    thanks



  • AVOID THE ?DO YOU WANTO TO REPLACE IT?? QUESTION