In Excel, there is no direct function to get the sheet name of the active sheet. Now the solution to this problem is to create a formula using multiple functions or to use a custom function created using the VBA. In this tutorial, you will learn both methods with examples. Use a Formul...
2. 在VBA编辑器中依次点击【插入】-【模块】: 3. 在右边的空白编辑器中输入以下VBA代码: Sub SaveWorkbookAsReadOnly() Dim wb As Workbook Dim filePath As String 'Get the active workbook Set wb = ActiveWorkbook 'Get the file path of the workbook filePath = wb.Path & "\" & wb.Name 'Save...
提取工作表名字 Sub GetShtByVba() Dim sht As Worksheet, k As Long Application.ScreenUpdating = False k = 1 Range("a:b").Clear '清空数据Range("a:a").NumberFormat = "@" '设置文本格式 For Each sht In Worksheets '遍历工作表取表名 k = k + 1 Cells(k, 1) = sht.Name Next Range(...
LEN(CELL(“filename”))-FIND(“]”,CELL(“filename”))The number returned by the FIND function is subtracted from the entire length of the full path text string returned by the LEN function. The result is the length of the name of the active worksheet. The result is passed to the RIG...
oftheworksheetisreturnedintheformof[Book1]sheet1. Otherwise,onlythefilenameoftheworkbookisreturned. Workbookfilenamedoesnotincludedrive,directory,orwindow number.ItisusuallybesttouseGET.DOCUMENT(76) AndGET.DOCUMENT(88)toreturnthefilenameoftheactive ...
In Application.Workbooks 'Loops through the workbooks.Debug.Print wb.Name If wb.Name Like...
Sheets(1).Range("A1")Wb2.Sheets(1).Name=Wb1.ActiveSheet.Name 'Below code willgetthe ...
Sub case_1() Sheet1.Range("c2").Select End Sub 如下就不会报错: Sub case_1() Sheet1.Select Sheet1.Range("c2").Select End Sub Cells指定单元格对象: (跳转到指定单元格搭配select使用) 八、VBA中的选区问题 Selection:当前选区,表示当前选中的单元格区域 ActiveCell:活动单元格,有且仅有一个 UsedRa...
SheetBeforeDoubleClick 事件:当双击任何工作表时发生此事件,此事件先于默认的双击操作发生。 SheetBeforeRightClick 事件:右键单击任一工作表时发生此事件,此事件先于默认的右键单击操作。 SheetCalculate 事件:在重新计算工作表时或在图表上绘制更改的数据之后发生此事件。
MsgBox "The name of the active sheet is " & ActiveSheet.Name 下面的示例将活动工作表复制用户指定的次数并放置在Sheet1之前。 Sub CopyActiveSheet() Dim x As Integer x = InputBox("Enter number of times to copy active sheet") For numtimes = 1 To x ' Put copies in front of Sheet1. Activ...