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(...
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...
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...
今天给大家分享一个使用VBA制作的日期控件,可以便捷地输入日期:使用方法,把下图所示窗体、类模块拖到你的文件里,再把sheet1的代码复制到相应的表格代码窗里:代码比较多,这里就不贴了,感兴趣的看示例文件吧。代码简析:一、建立一个类模块DateControl,以下是各个子程序的作用:Property Get myDate() As Date...
In Application.Workbooks 'Loops through the workbooks.Debug.Print wb.Name If wb.Name Like...
oftheworksheetisreturnedintheformof[Book1]sheet1. Otherwise,onlythefilenameoftheworkbookisreturned. Workbookfilenamedoesnotincludedrive,directory,orwindow number.ItisusuallybesttouseGET.DOCUMENT(76) AndGET.DOCUMENT(88)toreturnthefilenameoftheactive ...
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...
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...
Sheets(1).Range("A1")Wb2.Sheets(1).Name=Wb1.ActiveSheet.Name 'Below code willgetthe ...