Solved

How To Rename A Spreadsheet And Save The Worbook To A Specific File Location

Posted on 2011-03-23
2
244 Views
Last Modified: 2012-05-11
I have created and opened a new Excel spreadsheet using COM in Visual Studio 2010 C++.  How can I rename a sheet in the workbook and how can I save the workbook to a specific location?  I made this worth 500 because I put 2 questions in here but I'm pretty sure they are easy answers.  I just don't know the correct method to use or where to look to find a list of methods available through COM for Excel.

XL.CreateInstance(L"Excel.Application");
XL->Visible = true;
XL->Workbooks->Add();
Excel::_WorkbookPtr p_workbook=XL->ActiveWorkbook;
Excel::_WorksheetPtr pSheet = p_workbook->ActiveSheet;

Open in new window

0
Comment
Question by:rgrguric
  • 2
2 Comments
 

Accepted Solution

by:
rgrguric earned 0 total points
ID: 35235083
Looks like I'm gonna answer my own question!  

To rename a sheet in Excel through C++ COM:

Excel::_WorksheetPtr hosenSheet(XL->Worksheets->Item[7]); //Stores ptr to Sheet 7 as chosenSheet
chosenSheet->Name = "Compat Rules"; //Renames Sheet7 to Compat Rules

Open in new window


And finally to save the workbook to a specific location:

char outputPath[200];
char* wndwsUserID = getenv("USERNAME"); //Gets current user logon name for windows
strcpy(outputPath,"C:\\Documents and Settings\\");
strcat(outputPath, wndwsUserID); 
strcat(outputPath,"\\Desktop\\test.xls");

Open in new window

0
 

Author Closing Comment

by:rgrguric
ID: 35235093
No one else posted any comments so I work on this all weekend and came up with a solution!
0

Featured Post

ScreenConnect 6.0 Free Trial

Want empowering updates? You're in the right place! Discover new features in ScreenConnect 6.0, based on partner feedback, to keep you business operating smoothly and optimally (the way it should be). Explore all of the extras and enhancements for yourself!

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
PDF library for Delphi 2 121
ASP.net build a IF/Then Walkthrough Guide 1 212
Setup project 6 72
VB.NET - how to detect if a file is being used by another process 9 121
When writing generic code, using template meta-programming techniques, it is sometimes useful to know if a type is convertible to another type. A good example of when this might be is if you are writing diagnostic instrumentation for code to generat…
This article will show you some of the more useful Standard Template Library (STL) algorithms through the use of working examples.  You will learn about how these algorithms fit into the STL architecture, how they work with STL containers, and why t…
The goal of the tutorial is to teach the user how to use functions in C++. The video will cover how to define functions, how to call functions and how to create functions prototypes. Microsoft Visual C++ 2010 Express will be used as a text editor an…
The goal of the video will be to teach the user the concept of local variables and scope. An example of a locally defined variable will be given as well as an explanation of what scope is in C++. The local variable and concept of scope will be relat…

810 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