Get a worksheet name using Excel VBA

后端 未结 6 915
名媛妹妹
名媛妹妹 2021-01-08 01:29

I would like to create an user-defined function in Excel that can return the current worksheet. I could use the

sheetname = Activ         


        
6条回答
  •  余生分开走
    2021-01-08 01:53

    Sub FnGetSheetsName()
    
        Dim mainworkBook As Workbook
    
        Set mainworkBook = ActiveWorkbook
    
        For i = 1 To mainworkBook.Sheets.Count
    
        'Either we can put all names in an array , here we are printing all the names in Sheet 2
    
        mainworkBook.Sheets("Sheet2").Range("A" & i) = mainworkBook.Sheets(i).Name
    
        Next i
    
    End Sub
    

提交回复
热议问题