首页 文章

在Outlook中格式化日期时是否有办法强制使用区域设置?

提问于
浏览
0

我想知道是否有一个等同于 "[$-409]mmmm yyyy" 的Outlook VBA,它允许Excel在您想要的语言环境中显示日期 .
Format(Date, "[$-409]mmmm yyyy") 只是被静默忽略,只显示在系统区域设置中(我需要在两个不同的位置使用2个不同的区域设置,因此不能选择更改系统区域设置) .

编辑:我的问题实际上几乎是this one的重复,似乎在应用程序Outlook或PowerPoint中都不可能 .

1 回答

  • 0

    对不起,我没有在评论中明确说明 .

    当您在格式中包含“$ -409”时,您决定需要美国格式日期 . Excel可以帮助您创建美国格式的日期,但它无法帮助您确定所需的格式日期 .

    是你必须确定杰西获得美国约会,约翰获得英国约会,雅克获得法国约会 . 做出决定后,VB会在格式化日期时接受国家/地区代码,但我不相信VBA会提供任何此类功能 . 由于您只有两个区域设置,我建议您自己进行转换 .

    Option Explicit
    Sub Demo()
    
     Dim Prompt As String
     Dim Recipient As String
     Dim MonthsFrench() As Variant
     Dim Today As Date
    
     Today = Now()
     MonthsFrench = VBA.Array("", "Janvier", "Févier", "Mars", "Avril", "Mai", "Juin", _
                              "Juillet", "Auguste", "Septembre", "Octobre", "Novembre", "Décembre")
     ' I have used VBA.Array so lower bound is zero regardless of option base setting
    
     Debug.Print Format(Today, "d mmmm yyyy")
     Debug.Print Format(Today, "mmmm d, yyyy")
     Debug.Print Day(Today) & " " & MonthsFrench(Month(Today)) & " " & Year(Today)
    
     Do While True
       If Recipient = "" Then
         Prompt = "Recipient name?"
       Else
         Prompt = "Last recipient, " & Recipient & " preferred date is "
         Select Case Recipient
           Case "Jesse"
             Prompt = Prompt & Format(Today, "mmmm d, yyyy")
           Case "John"
             Prompt = Prompt & Format(Today, "d mmmm yyyy")
           Case "Jacque"
             Prompt = Prompt & Day(Today) & " " & MonthsFrench(Month(Today)) & " " & Year(Today)
           Case Else
             Prompt = "Last recipient not known"
         End Select
         Prompt = Prompt & vbLf & "Next recipient name?"
       End If
       Recipient = InputBox(Prompt)
       If Recipient = "" Then
         Exit Sub
       End If
     Loop
    
    End Sub
    

相关问题