我有正确运行的代码,可以打开新的工作表(来自模板),并在主工作表中使用活动单元格的名称重命名它(A列中的公司名称)。
Sub HistorySupplies()
Dim wb As Workbook
Dim ws As Worksheet
Dim activeWB As Workbook
Dim FilePath As String
Dim ShtName As String
Application.ScreenUpdating = False
Application.DisplayAlerts = False
Set activeWB = Application.ActiveWorkbook
FilePath = "C:\Users\DELL\AppData\Roaming\Microsoft\Szablony\HistoriaDostaw1.xltm"
On Error Resume Next
ShtName = ActiveCell.Value2
Set wb = Application.Workbooks.Open(FilePath)
wb.Worksheets(1).Copy After:=activeWB.Sheets(activeWB.Sheets.Count)
activeWB.Activate
activeWB.Sheets(activeWB.Sheets.Count).Name = ShtName
wb.Close False
Application.ScreenUpdating = True
Application.DisplayAlerts = True
End Sub
我需要的是:
我知道有多个类似的线程,但我不知道如何为我的代码实现工作表名称检查。