在 Excel VBA 中,我试图将“月份的阿拉伯语名称”放入变量中,我找到了一种方法。但我的方法需要一个缓冲区单元格来放置值、更改单元格格式、检索单元格的文本值,然后将该值放入变量中。
这是我的 VBA 代码:
Sub GetArabicName()
Sheets("Sheet1").Cells(1, 1).Value = date()
Sheets("Sheet1").Cells(1, 1).NumberFormat = "[$-10A0000]mmmm;@"
ArabicMonth = Sheets("Sheet1").Cells(1, 1).Text
MsgBox ArabicMonth & " The Arabic Name of the Month"
End Sub
是否有更简单的方法使用 VBA 而不使用缓冲单元来执行此操作?另外,我怎样才能让 MsgBox
显示阿拉伯值而不是“??????”
提前谢谢您。
最佳答案
我无法消除对辅助单元的需要,但是这会得到一个消息类型的框来显示文本:
Public Declare Function MessageBoxU Lib "user32" Alias "MessageBoxW" _
(ByVal hwnd As Long, _
ByVal lpText As Long, _
ByVal lpCaption As Long, _
ByVal wType As Long) As Long
Sub GetArabicName()
Dim ArabicMonth As String
With Sheets("Sheet1").Cells(1, 1)
.Value = Date
.NumberFormat = "[$-10A0000]mmmm;@"
.Font.Name = "Arial Unicode MS"
ArabicMonth = .Text
End With
MessageBoxU 0, StrPtr(ArabicMonth), StrPtr("MsgBox Substitute"), 0
MsgBox ArabicMonth & " The Arabic Name of the Month"
End Sub
改编自:
编辑#1:
根据 Axel Richter 的出色建议,这消除了对辅助单元的需要:
Sub GetArabicNames_II()
Dim ArabicMonth As String
ArabicMonth = Application.WorksheetFunction.Text(Date, "[$-10A0000]mmmm;@")
MessageBoxU 0, StrPtr(ArabicMonth), StrPtr("MsgBox Substitute"), 0
End Sub
关于vba - 如何使用 Excel VBA 获取阿拉伯月份名称,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39945488/