Click here to Skip to main content
15,896,915 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Hi I have an excel sheet as an embedded resource in my program. I want to create a copy of that sheet. The sheet also has some embedded tables (formatting) tables in it. So, when I manually copy this sheet, excel would prompt with messages asking whether to rename the formatting table
Thanks

What I have tried:

Dim oExcel As New Excel.Application
Dim oBook As Excel.Workbook
Dim oSheet As Excel.Worksheet = Nothing
oBook = oExcel.Workbooks.Open("C:\File.xlsx")

Tried the following and none of them worked:
oSheet.Copy("sheet1")
oSheet.Sheets1.Copy(After:=oSheet.Sheets2)
Posted
Updated 25-Jun-16 18:17pm

1 solution

Your first problem is
VB
Dim oSheet As Excel.Worksheet = Nothing

, before using oSheet, you must set it to the sheet you want to copy.
In
VB
oSheet.Sheets1.Copy(After:=oSheet.Sheets2)

oSheet os not a Sheet and Sheets1 and Sheets2 do not exist.

There is an easy way to get a working macro for anything you can do on keyboard/mouse: Ask Excel to record a new macro and then open VBA editor to see the source code, you only have to adapt to your real usage.

Nota: your question is rather confuse, remember we don't see your screen and we don't have your WorkBook.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900