将工作表保存到使用工作表标题为文件命名的位置

时间:2018-09-27 21:21:40

标签: excel vba excel-vba

我写了一个按钮-

Private Sub CommandButton1_Click()

    Dim path As String
    Dim filename1\ As String

    path = C:\Users\Barb\Desktop\demo\"
    filename1 = Range("C4").Text
    Application.DisplayAlerts = False
    ActiveWorkbook.SaveAs Filename1=path & filename1 & ".xlsx", 
    FileFormatxlOpenXMLWorkbook
    Application.DisplayAlerts = True
    ActiveWorkbook.Close

End Sub

在保存工作表以使用工作表标签的标题时,我怎么知道

2 个答案:

答案 0 :(得分:1)

假设您正在谈论ActiveSheet,请更改:

filename1 = Range("C4").Text

至:

filename1 = ActiveSheet.Name

答案 1 :(得分:1)

例如:

filename1 = sheets(1).name

filename1 = activesheet. name