Hi All, By using fileexist, we can find if a file exists or not. If it exists then we can open it using fopen and write to it using fput and fwrite. But, s there a way to create an excel file if doesn't exist and then open it and write to it? I want to write to it by renaming the sheet. I want to open it in append mode to add the records. I want to do all this in a macro. Can anyone help? So, far I am trying the following code, but after running this macro, when I try to open the excel file, getting an error message as shown in the screenshot: Code: %macro test; %let filrf=myfile1; %let rc=%sysfunc(filename(filrf, C:\practice\Missing_records_in_source.xlsx)); %let fid1=%sysfunc(fopen(&filrf, A, 0, V)); %let message = The file is empty; %let rc=%sysfunc(fput(&fid1, &message)); %if (%sysfunc(fwrite(&fid1,)) ne 0) %then %put %sysfunc(sysmsg()); %let rc=%sysfunc(fclose(&fid1)); %mend test; %test In the log: 944 %macro test; 945 %let filrf=myfile1; 946 %let rc=%sysfunc(filename(filrf, C:\practice 946! \Missing_records_in_source.xlsx)); 947 %let fid1=%sysfunc(fopen(&filrf, A, 0, V)); 948 %let message = The file is empty; 949 950 %let rc=%sysfunc(fput(&fid1, &message)); 951 %if (%sysfunc(fwrite(&fid1,)) ne 0) %then %put %sysfunc(sysmsg()); 952 953 %let rc=%sysfunc(fclose(&fid1)); 954 %mend test; 955 956 %test SYMBOLGEN: Macro variable FILRF resolves to myfile1 SYMBOLGEN: Macro variable FID1 resolves to 5 SYMBOLGEN: Macro variable MESSAGE resolves to The file is empty SYMBOLGEN: Macro variable FID1 resolves to 5 SYMBOLGEN: Macro variable FID1 resolves to 5 Error when tried to open the excel file: Thanks
... View more