如何从Excel工作表复制并粘贴到控制台应用程序中的另一个工作簿 [英] How to copy and paste from excel work sheet to another workbook in console application

查看:91
本文介绍了如何从Excel工作表复制并粘贴到控制台应用程序中的另一个工作簿的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

嗨朋友,



这里我在excel1中的数据粘贴到特定位置的excel2时出错。错误是:



Microsoft.VisualBasic.dll中发生了'System.MissingMemberException'类型的未处理异常附加信息:类型'范围内的公共成员'粘贴' '找不到。'



任何人都可以帮助我。下面显示了我的代码。



任何人都可以快速回复...这真的很紧急......



  Sub  Main()

' ~~>打开源工作簿。更改适用的路径和文件名
xlWorkBook = xlApp.Workbooks.Open( C:\\ \\ Users\Thaneskumar \Desktop\Copy of SBL_Release_Yield Loss Update_HL_20150813072418.xlsx

MyDate = Format(现在, dd
MyMonth =格式(现在, MM
MyYear =格式(现在, yyyy

Mydirectory = C:\ Users \Thaneskumar \Desktop \\ \\ test

MyExtension = 。xlsx

MyFileName = Mydirectory + MyDate + MyMonth + _ + My Year + MyExtension

ExcelApp = CreateObject( Excel.Application

xlWorkBook2 = ExcelApp.Workbooks.Add
ExcelSheet = xlWorkBook2.Worksheets( 1

' ~~>显示Excel
xlApp.Visible = True

' ~~>设置源工作表
xlWorkSheet = xlWorkBook.Sheets( SBL趋势(每日)
' ~~>设置目标工作表
xlWsheet2 = xlWorkBook2.Sheets( Sheet1

' ~~>设置源范围
xlSourceRange = xlWorkSheet.Range( A18:Q22
' '~~>设置目的地范围
xlDestRange = xlWsheet2.Range( A3

' ~~>复制并粘贴范围
xlSourceRange.Copy()
xlDestRange。选择()
xlDestRange.Paste()




generategraph()
xlWorkBook2.SaveAs(MyFileName)

xlWorkBook2.Close()
xlWorkBook.Close()

结束

解决方案

< blockquote>至少 - VBA和VB.NET编程之间的差异很小。看看这里:将代码从VBA转换为Visual Basic .NET [ ^ ]



点击链接了解更多有关 Range.PasteSpecial [ ^ ]方法。


Hi Friends,

Here i have error when the data in excel1 paste into the excel2 at specific location. The error is:

"An unhandled exception of type 'System.MissingMemberException' occurred in Microsoft.VisualBasic.dll Additional information: Public member 'Paste' on type 'Range' not found."

can anyone help me. Below is shows my code.

Can anyone response in fast please...it is really urgent...

Sub Main()

        '~~> Opens Source Workbook. Change path and filename as applicable
        xlWorkBook = xlApp.Workbooks.Open("C:\Users\Thaneskumar\Desktop\Copy of SBL_Release_Yield Loss Update_HL_20150813072418.xlsx")

        MyDate = Format(Now, "dd")
        MyMonth = Format(Now, "MM")
        MyYear = Format(Now, "yyyy")

        Mydirectory = "C:\Users\Thaneskumar\Desktop\test"

        MyExtension = ".xlsx"

        MyFileName = Mydirectory + MyDate + MyMonth + "_" + MyYear + MyExtension

        ExcelApp = CreateObject("Excel.Application")

        xlWorkBook2 = ExcelApp.Workbooks.Add
        ExcelSheet = xlWorkBook2.Worksheets(1)

        '~~> Display Excel
        xlApp.Visible = True

        '~~> Set the source worksheet
        xlWorkSheet = xlWorkBook.Sheets("SBL Trend(daily)")
        '~~> Set the destination worksheet
        xlWsheet2 = xlWorkBook2.Sheets("Sheet1")

        '~~> Set the source range
        xlSourceRange = xlWorkSheet.Range("A18:Q22")
        ''~~> Set the destination range
        xlDestRange = xlWsheet2.Range("A3")

        '~~> Copy and paste the range
        xlSourceRange.Copy()
        xlDestRange.Select()
        xlDestRange.Paste()




        generategraph()
        xlWorkBook2.SaveAs(MyFileName)

        xlWorkBook2.Close()
        xlWorkBook.Close()

    End

解决方案

There's - at least - few differences between VBA and VB.NET programming. Have a look here: Converting Code from VBA to Visual Basic .NET[^]

Follow the link for further details about Range.PasteSpecial[^] method.


这篇关于如何从Excel工作表复制并粘贴到控制台应用程序中的另一个工作簿的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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