如何通过vba将日期从excel复制到powerpoint并强制采用英文格式而不考虑本地格式?

问题描述 投票:0回答:1

我需要将 Excel 中的日期传递到 PowerPoint,但它们不断被格式化为我的本地格式(葡萄牙语)。我需要强制它们采用英文格式,并且一直在搜索,但没有解决方案对我有用。

我已经尝试过 SetThreadLocale,更改 excel 上的格式并通过代码强制它,但我试图避免最后一个。

这是我的代码:

Sub ExportToPPT()
    Dim ppt As Object
    Dim pptpres As Object

    Dim presentationDate As Date
    presentationDate = #3/21/2024#

    Set ppt = CreateObject("PowerPoint.Application")

    Root = "C:\PPT_REPORTS\"
    template = Root & "ppt_template.pptx"
    Set pptpres = ppt.Presentations.Open(Filename := template)
    
    pptpres.slides(1).Shapes.Item(2).TextFrame.TextRange.Text = Format(presentationDate, "mmmm dd")
End Sub

结果如下:Image says

我想强制它为“3 月 21 日”而不更改 Windows 的区域格式

excel vba powerpoint locale
1个回答
0
投票

日期月份

  • 使用英语月份数组。
Dim EngMonths() As Variant: EngMonths = VBA.Array( _
    "January", "February", "March", "April", "Mai", "June", _
    "July", "August", "September", "October", "November", "December")
    

... .Text = EngMonths(Month(presentationDate) - 1) _
    & " " & Format(presentationDate, "dd")
  • 使用以下命令打开和关闭 Excel,需要一些时间。 IMO,荒谬。
Dim pDate As String
With CreateObject("Excel.Application")
    pData = .Text(Date, "[$-409]mmmm dd")
End With
© www.soinside.com 2019 - 2024. All rights reserved.