How to close any file without saving it?

Hello, I want to know what is the command for closing a particular type of file without any requist to save it.
i.e. I want to know:
  • How can I close all files from any type of application e.g. close all txt files that are open?
  • How can I close those files automatically without saving?
I already know, for closing an excel file the following commands are used:
However when I use code, the application, (in this case excel) asks me if I want to save my file.
try
Excel = actxGetRunningServer('Excel.Application');
Excel.Quit; % Shut down Excel.
catch
end

Antworten (1)

Chunru
Chunru am 13 Aug. 2021

0 Stimmen

Is "fclose all" what you want?

4 Kommentare

Hannah
Hannah am 13 Aug. 2021
I think "fclose all" closes all open files, right? But I want to close files from a specified application e.g. close all txt files or close all Excel files.
OS has no idea if a file is excel or txt files. User must maintain a list of files. For examples:
fidtxt(1) = fopen('textfile1', 'w');
fidtxt(2) = fopen('textfile2', 'w');
fidxls(1) = fopen('excelfile1', 'w');
fidxls(2) = fopen('excelfile2', 'w');
arrayfun(@(x) fclose(x), fidtxt); % close all txt files
arrayfun(@(x) fclose(x), fidxls); % close all txt files
Hannah
Hannah am 13 Aug. 2021
Is it not possible to use the handle 'actxGetRunningServer' to close a specific application?
Chunru
Chunru am 13 Aug. 2021
Bearbeitet: Chunru am 13 Aug. 2021
Excel = actxGetRunningServer('Excel.Application') will run the external exel server. You can check https://docs.microsoft.com/en-us/office/vba/api/overview/excel to see how the external server Quit the file without confirmation.
Try the follwing to see if you can skip the confirmation.
Excel = actxGetRunningServer('Excel.Application');
Excel.DisplayAlerts = false;
Excel.Quit
On the other hand, if you can replace the actx and use xlswrite, then you will not have the problem of confirming quit.

Melden Sie sich an, um zu kommentieren.

Gefragt:

am 13 Aug. 2021

Bearbeitet:

am 13 Aug. 2021

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by