Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Delphi6 OleApplication Excel How to add new worksheets to active workbook.

Posted on 2004-04-05
1
Medium Priority
?
739 Views
Last Modified: 2010-04-16
Have a need to have seven initial worksheets in a workbook, but how do you add another 4 to the three as default? Both the 'add on opening' workbook and the 'add on fly' to an open workbook methods are required please. Code so far...

procedure ExcelOpen(Sender: TObject; Excelname:String);
begin
  // If the workbook exists, open it, else create an instance of it.
  OleApplication := CreateOleObject('Excel.Application');
  OleApplication.visible :=false;
  if fileexists(dataq.outdir+'\'+Excelname) then
  begin
    OleWorkBook:=OleApplication.WorkBooks.open(dataq.outdir+'\'+Excelname);
  end else begin
    OleWorkBook:=OleApplication.WorkBooks.Add;
//    what is the code that should generate the total 7 worksheets?
  end;
end;
 
0
Comment
Question by:mornao
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
1 Comment
 
LVL 26

Accepted Solution

by:
Russell Libby earned 400 total points
ID: 10757567
The following code will ensure that each workbook you open has 7 worksheets available.

Hope this helps,
Russell



procedure ExcelOpen(Sender: TObject; Excelname:String);
var  OleApplication:   OleVariant;
     OleWorkBook:      Olevariant;
     dwIndex:          Integer;
begin

  // If the workbook exists, open it, else create an instance of it.
  OleApplication:=CreateOleObject('Excel.Application');
  OleApplication.Visible:=False;
  if fileexists(dataq.outdir+'\'+Excelname) then
    OleWorkBook:=OleApplication.WorkBooks.open(dataq.outdir+'\'+Excelname)
  else
     OleWorkBook:=OleApplication.WorkBooks.Add;
  // what is the code that should generate the total 7 worksheets?
  for dwIndex:=OleWorkBook.WorkSheets.Count to 6 do
  begin
     OleWorkBook.Worksheets.Add;
  end;

end;
0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction The parallel port is a very commonly known port, it was widely used to connect a printer to the PC, if you look at the back of your computer, for those who don't have newer computers, there will be a port with 25 pins and a small print…
Introduction I have seen many questions in this Delphi topic area where queries in threads are needed or suggested. I know bumped into a similar need. This article will address some of the concepts when dealing with a multithreaded delphi database…
Sometimes it takes a new vantage point, apart from our everyday security practices, to truly see our Active Directory (AD) vulnerabilities. We get used to implementing the same techniques and checking the same areas for a breach. This pattern can re…
In a question here at Experts Exchange (https://www.experts-exchange.com/questions/29062564/Adobe-acrobat-reader-DC.html), a member asked how to create a signature in Adobe Acrobat Reader DC (the free Reader product, not the paid, full Acrobat produ…
Suggested Courses

636 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question