简体   繁体   中英

Excel worksheet name

I want to make a macro that copies data from one sheet to another. No problem, but I named the sheet with an emoji.

How can I tell VBA which sheet he has to use if the name of the sheet is for example: 🏠

Thanks in advance

您可以使用AscW函数为项找到合适的unicode值,并使用它来查找正确的工作表

To find the name of any given worksheet, activate the worksheet, open the VBA Editor (Alt+F11), open the Immediate Window (Ctrl+G) and type the following:

? ActiveSheet.Name

If the name for some reason is nonsensical, and only consists of a single character, run ? Asc(ActiveSheet.Name) ? Asc(ActiveSheet.Name) to get the ASCII value.

Referencing an ASCII value in VBA can be done by calling Chr(putValueHere) , for example like this:

Worksheets(1).Name = Chr(50)

If you have a plethora of sheets, you can print all of them by running this code:

Sub SheetNamePrinter
    For i = 1 To Worksheets.Count
        Debug.Print Worksheets(i).Name
    Next i
End Sub

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM