Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Programmatically Add A New Excel Worksheet

Status
Not open for further replies.

Hackster

Programmer
Mar 28, 2001
173
US
I can open and manipulate Excel workbooks easily, but I'm not faced with the task of programmatically adding a new worksheet to an existing spreadsheet. How would I do that?
 
Hi,
Code:
    Dim objExcelApp As Excel.Application
    Dim xlsExcelSheet As Excel.Worksheet

    ' Create the Excel application.
    Set objExcelApp = New Excel.Application
    'nextline opens your workbook
    objExcelApp.Workbooks.Open "Your Excel Sheet"
    objExcelApp.Visible = True
    
    ' Add the Excel spreadsheet.
    [red]objExcelApp.Worksheets.Add[/red]

The bit in [red]red[/red] is how to add the worksheet.

Hope this helps

Harleyquinn

---------------------------------
For tsunami relief donations
 
I feel like such a dufus. I was trying (and, of course, failing) to do .AddNew

Thanks
 
A general hint for VB interface with Excel is to try recording a macro in Excel first, then dissecting that code to produce what you need. It sorts out the right keywords and general syntax for you, and you can just trim to fit.

________________________________________________________________
If you want to get the best response to a question, please check out FAQ222-2244 first

For tsunami relief donations

'If we're supposed to work in Hex, why have we only got A fingers?'

for steam enthusiasts
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top