VB 编译器无法识别 xlPasteValues
VB Compiler can not recognize xlPasteValues
我有这个简单的 VB.NET 代码可以从一个工作表复制范围并粘贴到另一个工作表,仅粘贴值 :
Dim xlApp As Microsoft.Office.Interop.Excel.Application = New Microsoft.Office.Interop.Excel.Application
Dim xlWorkbook As Microsoft.Office.Interop.Excel.Workbook = xlApp.Workbooks.Open(in_Path)
'Define the Excel Source Sheet
Dim xlWorkSheetSource As Microsoft.Office.Interop.Excel.WorkSheet
xlWorkSheetSource = CType(xlWorkbook.Sheets(in_WorkSheetSource),Microsoft.Office.Interop.Excel.WorkSheet)
'Activate the Source Worksheet
xlWorkSheetSource.Activate()
Dim xlRange1 As Microsoft.Office.Interop.Excel.Range
xlRange1 = xlWorkSheetSource.Range("A13:O20")
xlRange1.Copy()
'Define the Excel Destination Sheet
Dim xlWorkSheetDestination As Microsoft.Office.Interop.Excel.WorkSheet
xlWorkSheetDestination = CType(xlWorkbook.Sheets(in_WorkSheetDestination),Microsoft.Office.Interop.Excel.WorkSheet)
'Activate the Source Worksheet
xlWorkSheetDestination.Activate()
xlWorkSheetDestination.Range("A1").PasteSpecial(xlPasteValues)
xlWorkbook.Save
xlWorkbook.Close
但是我有这个错误 :
No compiled code to run
error BC30451: 'xlPasteValues' is not declared. It may be inaccessible due to its protection level. At line 21
显然,xlPasteValues
不是要声明的变量。
还有其他方法可以完成吗?
我正在使用命名空间:
Microsoft.Office.Interop.Excel
在 VB.Net 中(与 VBA 不同)您必须限定枚举值。所以改变这一行:
xlWorkSheetDestination.Range("A1").PasteSpecial(xlPasteValues)
对此:
xlWorkSheetDestination.Range("A1").PasteSpecial(xlPasteType.xlPasteValues)
我有这个简单的 VB.NET 代码可以从一个工作表复制范围并粘贴到另一个工作表,仅粘贴值 :
Dim xlApp As Microsoft.Office.Interop.Excel.Application = New Microsoft.Office.Interop.Excel.Application
Dim xlWorkbook As Microsoft.Office.Interop.Excel.Workbook = xlApp.Workbooks.Open(in_Path)
'Define the Excel Source Sheet
Dim xlWorkSheetSource As Microsoft.Office.Interop.Excel.WorkSheet
xlWorkSheetSource = CType(xlWorkbook.Sheets(in_WorkSheetSource),Microsoft.Office.Interop.Excel.WorkSheet)
'Activate the Source Worksheet
xlWorkSheetSource.Activate()
Dim xlRange1 As Microsoft.Office.Interop.Excel.Range
xlRange1 = xlWorkSheetSource.Range("A13:O20")
xlRange1.Copy()
'Define the Excel Destination Sheet
Dim xlWorkSheetDestination As Microsoft.Office.Interop.Excel.WorkSheet
xlWorkSheetDestination = CType(xlWorkbook.Sheets(in_WorkSheetDestination),Microsoft.Office.Interop.Excel.WorkSheet)
'Activate the Source Worksheet
xlWorkSheetDestination.Activate()
xlWorkSheetDestination.Range("A1").PasteSpecial(xlPasteValues)
xlWorkbook.Save
xlWorkbook.Close
但是我有这个错误 :
No compiled code to run
error BC30451: 'xlPasteValues' is not declared. It may be inaccessible due to its protection level. At line 21
显然,xlPasteValues
不是要声明的变量。
还有其他方法可以完成吗?
我正在使用命名空间:
Microsoft.Office.Interop.Excel
在 VB.Net 中(与 VBA 不同)您必须限定枚举值。所以改变这一行:
xlWorkSheetDestination.Range("A1").PasteSpecial(xlPasteValues)
对此:
xlWorkSheetDestination.Range("A1").PasteSpecial(xlPasteType.xlPasteValues)