Save Excel file

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • shoa

    #1

    Save Excel file

    Hello all

    I open a template Excel file as following
    -----------------------------
    im xlApp As Object

    Dim xlBook As Excel.Workbook

    Dim xlSheet As Excel.Worksheet

    xlApp = CreateObject("E xcel.Applicatio n")

    xlApp.Visible = True

    xlBook = xlApp.Workbooks .Open("C:\Datab ase\TempExcel\i nvoice.xls")

    xlSheet = xlBook.Workshee ts(1)

    ---------------

    Then I save this file as with a new name

    Dim fileName As String = "C:\aNewFile.xl s"

    xlBook.SaveAs(f ileName)

    -------------

    However, if there is existed file "aNewFile.x ls", there is a message
    informing that there is a file with the same name and ask me if I want to
    replace it. I do not want to have this message and want my application
    automatically replaces the old file. Coul you please tell me how to do that.

    Thank you very much for your help

    S.Hoa


  • Doug Bell

    #2
    Re: Save Excel file

    Shoa,
    Why don't you test for the existing file and delete it before you do the
    save.

    Doug

    "shoa" <son@slingshot. co.nz> wrote in message
    news:1118894312 .202141@ftpsrv1 ...[color=blue]
    > Hello all
    >
    > I open a template Excel file as following
    > -----------------------------
    > im xlApp As Object
    >
    > Dim xlBook As Excel.Workbook
    >
    > Dim xlSheet As Excel.Worksheet
    >
    > xlApp = CreateObject("E xcel.Applicatio n")
    >
    > xlApp.Visible = True
    >
    > xlBook = xlApp.Workbooks .Open("C:\Datab ase\TempExcel\i nvoice.xls")
    >
    > xlSheet = xlBook.Workshee ts(1)
    >
    > ---------------
    >
    > Then I save this file as with a new name
    >
    > Dim fileName As String = "C:\aNewFile.xl s"
    >
    > xlBook.SaveAs(f ileName)
    >
    > -------------
    >
    > However, if there is existed file "aNewFile.x ls", there is a message
    > informing that there is a file with the same name and ask me if I want to
    > replace it. I do not want to have this message and want my application
    > automatically replaces the old file. Coul you please tell me how to do[/color]
    that.[color=blue]
    >
    > Thank you very much for your help
    >
    > S.Hoa
    >
    >[/color]


    Comment

    • Peter Proost

      #3
      Re: Save Excel file

      With xlApp
      .DisplayAlerts = False
      xlBook.SaveAs(" C:\aNewFile.xls ")
      .DisplayAlerts = True
      End With

      I think this should do it

      Greetz Peter

      --
      Programming today is a race between software engineers striving to build
      bigger and better idiot-proof programs, and the Universe trying to produce
      bigger and better idiots. So far, the Universe is winning.


      "shoa" <son@slingshot. co.nz> schreef in bericht
      news:1118894312 .202141@ftpsrv1 ...[color=blue]
      > Hello all
      >
      > I open a template Excel file as following
      > -----------------------------
      > im xlApp As Object
      >
      > Dim xlBook As Excel.Workbook
      >
      > Dim xlSheet As Excel.Worksheet
      >
      > xlApp = CreateObject("E xcel.Applicatio n")
      >
      > xlApp.Visible = True
      >
      > xlBook = xlApp.Workbooks .Open("C:\Datab ase\TempExcel\i nvoice.xls")
      >
      > xlSheet = xlBook.Workshee ts(1)
      >
      > ---------------
      >
      > Then I save this file as with a new name
      >
      > Dim fileName As String = "C:\aNewFile.xl s"
      >
      > xlBook.SaveAs(f ileName)
      >
      > -------------
      >
      > However, if there is existed file "aNewFile.x ls", there is a message
      > informing that there is a file with the same name and ask me if I want to
      > replace it. I do not want to have this message and want my application
      > automatically replaces the old file. Coul you please tell me how to do[/color]
      that.[color=blue]
      >
      > Thank you very much for your help
      >
      > S.Hoa
      >
      >[/color]


      Comment

      Working...