I have dates in Excel that I need to pass to PowerPoint, but they keep getting formatted to my local formatting (portuguese). I need to force them to be in english format and have been searching but no solution worked for me.

I already tried SetThreadLocale, changing the formatting on excel and forcing it by code, but I was trying to avoid the last one.

Here's my code:

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

And here's the result:Image says "março 21"

I want to force it to be "March 21" without changing windows' regional formatting

1

There are 1 best solutions below

0
VBasic2008 On

Force US Month Name

Sub ExportToPPT()
    
    Const FOLDER_PATH As String = "C:\PPT_REPORTS\"
    Const FILE_NAME As String = "ppt_template.pptx"
    
    Dim presentationDate As Date: presentationDate = #3/21/2024#
    Dim DateString As String:
    DateString = Application.Text(presentationDate, "[$-409]mmmm dd")
    
    'Debug.Print DateString
    
    Dim FilePath As String: FilePath = FOLDER_PATH & FILE_NAME

    Dim ppt As Object: Set ppt = CreateObject("PowerPoint.Application")
    Dim pptpres As Object: Set pptpres = ppt.Presentations.Open(FilePath)
    
    pptpres.Slides(1).Shapes.Item(2).TextFrame.TextRange.Text = DateString

End Sub