-1

So I have written the below code that open my excel file and save it as text file

Dim xl As New Excel.Application
Dim xlBook As Excel.Workbook = xl.Workbooks.Open("C:\ExcelData.xlsx")
Dim xlSheet As Excel.Worksheet = xlBook.Sheets("Sheet1")

xlSheet.SaveAs("C:\Data.txt", Excel.XlFileFormat.xlTextWindows)

xlBook.Close

The problem is after it save the file i9t prompt me do you want to save changes and when I click Yes it overwrite the file with the latest opned sheet from the excel.

How can I stop it from overwriting and stop it from prompt me for changes?

pnuts
  • 58,317
  • 11
  • 87
  • 139

1 Answers1

2

If you add the following line at the start of your macro:

Application.DisplayAlerts = False

Then no dialog boxes will appear during its running. This will include the popup that shows when closing xlBook.

Phylogenesis
  • 7,775
  • 19
  • 27