如何使用VB.NET在Excel中复制工作表 [英] How do I copy a sheet in excel using VB.NET

查看:1396
本文介绍了如何使用VB.NET在Excel中复制工作表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Hi
我的程序中有一个excel表作为嵌入式资源。我想创建该表的副本。该表还包含一些嵌入式表(格式)表。因此,当我手动复制此工作表时,excel会提示消息,询问是否重命名格式化表格

谢谢



什么我试过了:



Dim oExcel As New Excel.Application

Dim oBook as Excel.Workbook

Dim oSheet As Excel.Worksheet = Nothing

oBook = oExcel.Workbooks.Open(C:\ .File.xlsx)



尝试以下操作并且没有一个工作:

oSheet.Copy(sheet1)

oSheet.Sheets1.Copy(After:= oSheet.Sheets2)

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)

推荐答案

你的第一个问题是

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



,在使用 oSheet 之前,您必须将其设置为您要复制的工作表。




, before using oSheet, you must set it to the sheet you want to copy.
In

oSheet.Sheets1.Copy(After:=oSheet.Sheets2)



oSheet os不是工作表而 Sheets1 并且 Sheets2 不存在。



有一种简单的方法可以为你能做的任何事情获得一个可用的宏在键盘/鼠标上:让Excel记录一个新的宏,然后打开VBA编辑器查看源代码,你只需要适应你的实际使用情况。



Nota :你的问题相当混乱,记得我们没有看到你的屏幕而我们没有你的工作簿。


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.


这篇关于如何使用VB.NET在Excel中复制工作表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆