View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.programming
Bernie Deitrick Bernie Deitrick is offline
external usenet poster
 
Posts: 5,441
Default Why system asks me to save change even after I call save method(VB.NET)

steellock,

Use this to close the workbook:
exwbook.Close False

HTH,
Bernie
MS Excel MVP

"steellock" wrote in message
...
I used below code to open and fill an Excel file automaically. After that,

save it.
However, after I call Workbook.SaveAs(Or Save), when I close the Excel

file. I always be asked "The content of this file is changed, do you want to
save it?"
But the content has already been saved indeed.
Then why that message is showed? How to clear it?

Dim ExcelForm As New Excel.Application
Dim exwbook As Excel.Workbook
Dim exsheet As Excel.Worksheet
Dim file As New FileInfo("C:\template.xls")

If file.Exists = True Then
file.Delete()
End If

Dim fs As FileStream = file.Create()
fs.Close()

ExcelForm = CreateObject("Excel.Application")
ExcelForm.Visible = True

exwbook = ExcelForm.Workbooks.Open("C:\template.xls")
exsheet = exwbook.Worksheets("template")

exsheet.Cells(1, 1) = ... ...

exwbook .SaveAs("C:\template.xls) 'Or exsheet.Save()