Hi, X Commands are disabled in our SAS server, and won't be enabled. With that, I'd like to know how can I execute a vb script I made for the consolidation of these multiple excel sheets. I know it's possible to fix the sequence using ODS tagsets, but since there is a lot of ongoing program development and revision, I prefer to perform the consolidation at the end of my SAS program.
VB Script sample as below:
Function Cpypaste (xlfile)
Dim xlfile_nm
xlfile_nm = xlfile
'MsgBox xlfile_nm
Set CopyFromWbk = objExcel.Workbooks.Open(FolderPath & xlfile_nm & ".xlsx")
'Worksheet.Name = xlfile_nm
Set ShToCopy = CopyFromWbk.Sheets(1)
ShToCopy.Copy CopyToWbk.Sheets(CopyToWbk.Sheets.Count)
CopyFromWbk.Close
End Function
Hi,
maybe something like this:
%macro consolidateXlsxSheets(FolderPath=,xlfile=,vbsFileName=);
%let saveOpt=%sysfunc(getOption(QUOTELENMAX));
options noquotelenmax;
data _null_;
file "&vbsFileName";
put " Dim objExcel ";
put " Dim FSO";
put " Dim objWorkBook";
put " Set objExcel = CreateObject(""Excel.Application"")";
put " Set FSO = CreateObject(""Scripting.FileSystemObject"")";
put " objExcel.DisplayAlerts = False";
put " Dim xlfile_nm";
put " xlfile_nm = &xlfile.";
put " 'MsgBox xlfile_nm";
put " Set CopyFromWbk = objExcel.Workbooks.Open(&FolderPath. & xlfile_nm & "".xlsx"")";
put " 'Worksheet.Name = xlfile_nm";
put " Set ShToCopy = CopyFromWbk.Sheets(1)";
put " ShToCopy.Copy CopyToWbk.Sheets(CopyToWbk.Sheets.Count)";
put " CopyFromWbk.Close";
put " objExcel.DisplayAlerts = True";
put " objExcel.Quit";
put " Set objExcel = Nothing";
put " FSO.DeleteFile(""&vbsFileName""), DeleteReadOnly";
put " Set FSO = Nothing";
run;
data _null_;
call system("""&vbsFileName"""); * 3 quotes in order to work with names containing spaces;
run;
options &saveOpt.;
%mend consolidateXlsxSheets;
%consolidateXlsxSheets(FolderPath=,xlfile=,vbsFileName=c:\xyz.vbs);
- Cheers -
Thanks! It's a working alternative to the X statement, but I'm still getting a Shell Escape not valid error.
@angeliquec wrote:
Hi, X Commands are disabled in our SAS server, and won't be enabled. With that, I'd like to know how can I execute a vb script I made for the consolidation of these multiple excel sheets. I know it's possible to fix the sequence using ODS tagsets, but since there is a lot of ongoing program development and revision, I prefer to perform the consolidation at the end of my SAS program.
VB Script sample as below:
Function Cpypaste (xlfile)
Dim xlfile_nm
xlfile_nm = xlfile
'MsgBox xlfile_nm
Set CopyFromWbk = objExcel.Workbooks.Open(FolderPath & xlfile_nm & ".xlsx")
'Worksheet.Name = xlfile_nm
Set ShToCopy = CopyFromWbk.Sheets(1)
ShToCopy.Copy CopyToWbk.Sheets(CopyToWbk.Sheets.Count)
CopyFromWbk.Close
End Function
If you are generating that output to multiple sheets from SAS then likely you could just change how the output is generated from SAS.
If using ODS tagsets.excelxp or ods excel then the SHEET_INTERVAL option controls how sheets are generated and likely use of NONE would send all of the output to a single sheet so the post processing is not needed.
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
Learn how use the CAT functions in SAS to join values from multiple variables into a single value.
Find more tutorials on the SAS Users YouTube channel.