2 Replies - 164 Views - Last Post: 02 February 2012 - 08:42 PM Rate Topic: -----

Topic Sponsor:

#1 m4_prashanth  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 3
  • Joined: 02-February 12

Problem in saving a Excel document after writting data to it

Posted 02 February 2012 - 10:18 AM

Hi there

I am new to VB.NET. I was developing a software with related to Excel, in which I have to write and SAVE the details at appropriate columns. I am currently having a problem in saving the data.

Private Sub Button1_Click_1(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click

        'Open
        Dim MyExcel As New Excel.Application
        MyExcel.Workbooks.Open("C:\Test\WalkAir.xls")

        'Extract
        MyExcel.Sheets("sheet1").Activate()
        MyExcel.Range("A77").Activate()

        MyExcel.DisplayAlerts = False


        If Form2.TextBox1.Text = "sucess" Then

            MyExcel.ActiveCell.Offset(1, 0).Activate()

        End If

        MyExcel.ActiveCell.Value = "Test"

        'Close
        MyExcel.SaveWorkspace()
        'MyExcel.Quit()
        'MyExcel.Workbooks.Close()

        'MyExcel.WriteXLS("WalkAir.xls")
        MyExcel.Workbooks.Close()
        MyExcel = Nothing



        Me.Hide()
        Form2.Show()



    End Sub
End Class


Very first time I debug the coding I haven't got much problem. But debugging it again gives me an Error AS:
"A file named 'Resume.XLW' already exits in this location. Do you want to replace it?"

I was able to see this since I have enabled the display alerts. Disabling it generates a save as window.

I would be much obliged if you can really help me in this issue

Best Regards.

Is This A Good Question/Topic? 0
  • +

Replies To: Problem in saving a Excel document after writting data to it

#2 Ionut  Icon User is offline

  • D.I.C Addict
  • member icon

Reputation: 327
  • View blog
  • Posts: 914
  • Joined: 17-July 10

Re: Problem in saving a Excel document after writting data to it

Posted 02 February 2012 - 01:17 PM

Use Save instead of SaveWorkspace. If the file is not save, Save will call SaveAs and a SaveFileDialog will appear. If you don't want this to happen, after you create the Workbook, call SaveAs with the path you want, then modify your workbook and call Save.
Was This Post Helpful? 0
  • +
  • -

#3 m4_prashanth  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 3
  • Joined: 02-February 12

Re: Problem in saving a Excel document after writting data to it

Posted 02 February 2012 - 08:42 PM

Hi there,

First of all thank you for your reply. My task is to look for a perticular colum in a workbook and locate a free cell (with some conditions) and write the data to that file.

Is there any way to SAVE THE DATA TO AN OPENED FILE.

Best regards
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1