Hi All,
I am just starting to work with excel files through x . As you may guess I know very little.
I have a template already made in Excel where I want to fill it with the data from the a selected production. this template is called routecard (RK).
since I don't want to modify the existing template I prefer to Open a copy of the template from X and modify from there.
Since I dont know exacly how to do that I am starting by creating a new file (RK_new), and copy each sheet from the template RK excel (RK)
here is what I'got so far. The problem is in the two last lines where I want to add a new sheet infolog shows: "COM Object, method add called with invalid parameters"
you help is greatly appreciated , I am quite sure there should be an easier solution just by somehow clone the workbooks
//******** template WorkBook SysExcelApplication appRK; SysExcelWorkbooks wbsRK; SysExcelWorkbook wbRK; SysExcelWorksheets wssRK; SysExcelWorksheet wsRK; SysExcelCells cellsRK; COMVariantType typeRK; FileName filename; //******** New WorkBook SysExcelApplication appRK_new; SysExcelWorkbooks wbsRK_new; SysExcelWorkbook wbRK_new; SysExcelWorksheets wssRK_new; SysExcelWorksheet wsRK_new; SysExcelCells cellsRK_new; COMVariantType typeRK_new; int rowRK_new; ItemId itemidRK_new; //******* Open the Original RK Template appRK = SysExcelApplication::construct(); wbsRK = appRK.workbooks(); filename = "W:\\Rutekort\\Poland\\RK_PL.xlsm"; try { wbsRK.open(filename,0,true); appRK.visible(true); } catch (Exception::Error) { throw error("File cannot be opened."); } wbRK = wbsRK.item(1); wssRK = wbRK.worksheets(); //******* Open New Excel for RK appRK_new = SysExcelApplication::construct(); wbsRK_new = appRK_new.workbooks(); wbRK_new = wbsRK_new.add(); // Creates new excel File wssRK_new = wbRK_new.worksheets(); //point to the its worksheets appRK_new.visible(true); //***** copying the first ws into the new workbook RK_new * ERROR wsRK_new = wssRK.itemFromNum(1); wssRK_new.add(wsRK_new);
I apologize guys , this was a silly question from my side,
Actually I have never made use of templates .xlts in Excel. What I needed to do was just save my excel as a template .xltm (enable for macros) this way when the user needs to open it from AX it will just make automatically a new one (with no track of the original path of the file which is what I like) .
other way is opening the excel from AX in the code as a Read-Only here the code for that:
that way I can make sure that the user wont modify the original file from where is beign opened.
Note: as far as I have been reading there is not predefault method in AX to copy or duplicates workbooks
Stay up to date on forum activity by subscribing. You can also customize your in-app and email Notification settings across all subscriptions.
André Arnaud de Cal... 291,151 Super User 2024 Season 2
Martin Dráb 229,963 Most Valuable Professional
nmaenpaa 101,156