Add sheets in Excel

Bart_Groot
Member Posts: 5
Hello,
I'm trying to insert a new sheet in Excel. If I use the statement:
Sheets.Add
then a new sheet is inserted before the other sheets. It should however be possible to insert sheets after another sheet with the following syntax
[IDISPATCH Add :=] xlSheets.Add([VARIANT Before][, VARIANT After][, VARIANT Count][, VARIANT Type])
I tryed
xlSheets.Add(0,1,2,-4167);
but this results in the message that the call to the function add failed. Method add of class sheets failed.
Does anyone know how to insert a new sheet after the existing one?
I'm trying to insert a new sheet in Excel. If I use the statement:
Sheets.Add
then a new sheet is inserted before the other sheets. It should however be possible to insert sheets after another sheet with the following syntax
[IDISPATCH Add :=] xlSheets.Add([VARIANT Before][, VARIANT After][, VARIANT Count][, VARIANT Type])
I tryed
xlSheets.Add(0,1,2,-4167);
but this results in the message that the call to the function add failed. Method add of class sheets failed.
Does anyone know how to insert a new sheet after the existing one?
0
Comments
-
Hi,
if you want to do this, maybe thats the right way:XlWksheet := XlSheets.Item(3); // The Sheet before the new should be added XlWksheet := XlSheets.Add(XlWkSheet);
The Parameters Before and After expect Worksheets.
Hope i could help
Greetings0 -
JoeK wrote:Hi,
if you want to do this, maybe thats the right way:XlWksheet := XlSheets.Item(3); // The Sheet before the new should be added XlWksheet := XlSheets.Add(XlWkSheet);
The Parameters Before and After expect Worksheets.
Hope i could help
Greetings
Hi
This is not wat i'm looking for. I only have one sheet and I want to add one after this one. Trying your code (after changing Item(3) to item(1) results in a new sheet before the existing one.
Greetings
Bart0 -
Yes, i know, just remind me. I got the same problem. My solution was to add the sheet (before all other sheets) and after i filled all sheets move the sheets in the correct order, like this:
xlwksheet := xlsheets.item(1); for L_Counter := 2 to xlsheets.count() do begin xlwksheet2 := xlsheets.item(L_Counter); xlwksheet2.move(xlwksheet); xlwksheet := xlwksheet2; end;
Hope i could help now...
The problem with the add method of the worksheets is that the parameters are: Before (WkSheet) , After (WkSheet) this parameter are optional, this means that if u want to add the sheet after the other the first parameter should be empty. I don´t know how to do this in nav.
Greetings0 -
Try using like this:
CREATE(xlApp); //Excel.Application xlApp.Workbooks.Open(excelfilename); //excelfilename : Text xlWb := xlApp.ActiveWorkbook; //xlWb - Excel Workbok xlSheetPlaceAfter:=xlWb.Worksheets.Item(Index); //from 1 to Worksheets count ; selecting sheet after which we want to place new sheet xlWsht := xlWb.Worksheets.Add(); //creating new sheet xlWsht.Name:='newsheet'; xlSheetPlaceAfter.Move(xlWsht); //Replacing places xlWb.Save; xlWb.Close(); CLEAR(xlApp);
if You want to change for example places of sheets 2 and 4 (indexes) (Sheet4 will be now on place Sheet2).
Numerical before:
1 2 3 4 5
Numerical after:
1 4 2 3 5CREATE(xlApp); //Excel.Application xlApp.Workbooks.Open(excelfilename); //excelfilename : Text xlWb := xlApp.ActiveWorkbook; //xlWb - Excel Workbok xlSheetPlaceAfter:=xlWb.Worksheets.Item(4); //from 1 to Worksheets count xlWsht:=xlWb.Worksheets.Item(2); xlSheetPlaceAfter.Move(xlWsht); //Replacing places xlWb.Save; xlWb.Close(); CLEAR(xlApp);
About Native Move usage, there are no Type.Missing type in Navision, so this thing I think won't work. Another way is to do with macros but...:)
Hope this helps.
Best wishes,
IB0 -
Thanx for all the advise. :-)
Bart Groot0
Categories
- All Categories
- 73 General
- 73 Announcements
- 66.6K Microsoft Dynamics NAV
- 18.7K NAV Three Tier
- 38.4K NAV/Navision Classic Client
- 3.6K Navision Attain
- 2.4K Navision Financials
- 116 Navision DOS
- 851 Navision e-Commerce
- 1K NAV Tips & Tricks
- 772 NAV Dutch speaking only
- 617 NAV Courses, Exams & Certification
- 2K Microsoft Dynamics-Other
- 1.5K Dynamics AX
- 320 Dynamics CRM
- 111 Dynamics GP
- 10 Dynamics SL
- 1.5K Other
- 990 SQL General
- 383 SQL Performance
- 34 SQL Tips & Tricks
- 35 Design Patterns (General & Best Practices)
- 1 Architectural Patterns
- 10 Design Patterns
- 5 Implementation Patterns
- 53 3rd Party Products, Services & Events
- 1.6K General
- 1.1K General Chat
- 1.6K Website
- 83 Testing
- 1.2K Download section
- 23 How Tos section
- 252 Feedback
- 12 NAV TechDays 2013 Sessions
- 13 NAV TechDays 2012 Sessions