我需要将 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
我想强制它为“3 月 21 日”而不更改 Windows 的区域格式
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")
Dim pDate As String
With CreateObject("Excel.Application")
pData = .Text(Date, "[$-409]mmmm dd")
End With