注:要添加COM组件 Microsoft Excel 11.0 Object Library 引用. 具体代码如下: using System; using System.Collections.Generic; using System.Text; using System.Data.SqlClient; using Excel; using System.Reflection; using System.Data; using System.Data.OleDb; namespace Re
Sub W() ' MsgBox "行数:" & Selection.Rows.Count Dim rows_count As Integer Dim rows_id As Integer Dim column_count As Integer column_count = Selection.Columns.Count '获取选择区域的列数 'MsgBox column_count '打印列数 rows_id = ActiveCell.
Private Sub Worksheet_SelectionChange(ByVal Target As Range) '可以直接sub(),不然选择就会触发vba Dim rows_count As Integer Dim rows_id As Integer Dim column_count As Integer Dim column_id As Integer column_count = Selection.Columns.Count '返回选择区域列数