VB
Microsoft 开发的一种面向对象的编程语言,其在 .NET Framework 上实现。 以前称为 Visual Basic .NET。
54 个问题
我想获取工作簿的 ActiveSheet 的名称。但以下命令不起作用:owb。ActiveSheet.Name. 我的思路是,自从 owb.ActiveSheet 返回一个工作表对象,我们可以对其使用 NAME 属性。但它不起作用。任何人都可以帮忙。
Imports System
Imports Microsoft.Office.Interop
Module Program
Dim oxl As Excel.Application
Dim owbs As Excel.Workbooks
Dim owb As Excel.Workbook
Dim osheet As Excel.Worksheet
Sub Main(args As String())
oxl = CreateObject("Excel.Application")
oxl.Visible = True
owb = oxl.Workbooks.Add
osheet = owb.Worksheets.Add(, , 5,)
Console.WriteLine("Active Sheet: {0}", owb.ActiveSheet.Name) 'This is not working
Console.ReadLine()
End Sub
End Module
Note:此问题总结整理于:How to get the name of the Active sheet in a workbook?
您可以尝试以下代码来获取工作簿的活动工作表。
Sub Main()
Dim oxl As Excel.Application
Dim owbs As Excel.Workbooks
Dim owb As Excel.Workbook
Dim osheet As Excel.Worksheet
oxl = CreateObject("Excel.Application")
oxl.Visible = True
owb = oxl.Workbooks.Open("C:\\Users\\username\\Desktop\\test.xlsx")
osheet = owb.ActiveSheet
Console.WriteLine("Active Sheet: {0}", osheet.Name)
Console.ReadLine()
End Sub
最好的问候,
杰克
如果答案是正确的解决方案,请点击“接受答案”并点赞。如果您对此答案有其他疑问,请点击“评论”。
注意:如果您想接收此线程的相关电子邮件通知,请按照我们文档中的步骤启用电子邮件通知