首页 > 解决方案 > 基于单元格值的工作簿名称

问题描述

所以,我有下面的代码,即隐藏所有列中包含 1 的行。每次必须更改文件名时,我都必须更改代码。

Workbooks("New R.M.S. Holiday Planner.xlsm").Worksheets("Planner").Activate

而不是New RMS Holiday Planner.xlsm,我想将它指向单元格 A1,我将在其中获得文件名。

可能这很愚蠢,但我无法解决。谢谢你的帮助。

Private Sub CheckBox1_Click()

If CheckBox1.Value = True Then
Application.ScreenUpdating = False
Application.EnableEvents = False
Application.Calculation = xlCalculationManual
Workbooks("New R.M.S. Holiday Planner.xlsm").Worksheets("Planner").Activate

With Sheets("Planner")
            Rows("11:1897").EntireRow.Hidden = False
            Application.ScreenUpdating = False
    For Each Cell In Range("BE10:BE1897")
    If Cell.Value = 1 Then Cell.EntireRow.RowHeight = 0.00001
Next Cell
Range("Y2:AF2").Select
    ActiveCell.FormulaR1C1 = "S&S Days"
    Range("A1").Select
 '   .Protect Password:="folder"
        Application.EnableEvents = True
    Application.ScreenUpdating = True
    Application.Calculation = xlCalculationAutomatic
End With
Else
If CheckBox1.Value = False Then
Application.ScreenUpdating = False
Application.EnableEvents = False
Application.Calculation = xlCalculationManual
Workbooks("New R.M.S. Holiday Planner.xlsm").Worksheets("Planner").Activate
With Sheets("Planner")
    For Each Cell In Range("BE10:BE1897")
    If Cell.Value = 1 Then Cell.EntireRow.RowHeight = 12.75
Next Cell
Range("Y2:AF2").Select
    ActiveCell.FormulaR1C1 = "All"
    Range("A1").Select
        Application.EnableEvents = True
    Application.ScreenUpdating = True
    Application.Calculation = xlCalculationAutomatic
End With
End If
End If
End Sub

标签: excelvba

解决方案


推荐阅读