vba - 如何使用 Excel VBA 获取阿拉伯月份名称

标签 vba excel arabic right-to-left

在 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

enter image description here

改编自:

Renaud Bompuis

编辑#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/

相关文章:

excel - 在 VBA Excel 中插入行

excel - 在事件的 Excel 文档中使用 VBA 从 powershell 连接到 Excel

c# - 使用 C# 读取 Excel 单元格

excel公式将分钟转换为百分之一

excel - 如何使用另一列中的值的引用来增加一列中的值

excel - 在excel中隐藏/取消隐藏合并的单元格

android - 如何在 Android 应用程序中保存 Excel 文件

visual-studio-2015 - 将阿拉伯语字符转换为大写

php - Laravel domPDF阿拉伯字符生成PDF错误

eclipse - 在同一行使用带有阿拉伯语和英语的 Eclipse