excel vba - VBA - object required error when setting .DisplayAlerts = False -
background:
i sas programmer (a statistical software), i'm using vba make excel play nicely sas. wrote program can execute in sas using following code:
*batch convert excel files csv files; %let xlsfile=c:\xlsfile.csv; %let csvfile=c:\csvfile.csv; %let worksheet=1; x 'cd "c:\location_of_vbsfile"'; x "vbsfile.vbs &xlsfile &worksheet &csvfile";
the program opens excel file, selects required sheet, replaces commas, carriage returns, , line feeds, saves file csv file can nicely import file sas.
problem:
i want to eliminate message boxes may produced. added application.displayalerts = false top of program prevent message boxes being displayed. however, following error, must wrong.
error: object required: 'displayalerts'
this code:
'1 - open excel dim oexcel dim obook set oexcel = createobject("excel.application") 'this added set oexcel.displayalerts = false set obook = oexcel.workbooks.open(wscript.arguments.item(0)) xlsheet = wscript.arguments.item(1)*1 '2 - select sheet obook.worksheets(xlsheet).select '3 - find , replace obook.worksheets(xlsheet).cells.replace ",", "" obook.worksheets(xlsheet).cells.replace chr(13), "" obook.worksheets(xlsheet).cells.replace chr(10), "" '4 - save obook.saveas wscript.arguments.item(2), 6 obook.close false set oexcel.displayalerts = true oexcel.quit
any suggestions?
don't use "set" before it. set used actual objects.
just:
oexcel.displayalerts = true
Comments
Post a Comment