×
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!
  • Students Click Here

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

Jobs

VBA for PPT - Open PPT File using Presentations.Open with Japanese Characters in Filename

VBA for PPT - Open PPT File using Presentations.Open with Japanese Characters in Filename

VBA for PPT - Open PPT File using Presentations.Open with Japanese Characters in Filename

(OP)
Hello,

I'm trying to make some VBA code work which scans a directory full of PPT files and opens them to perform some actions. The problem is that some of the PPT filenames have Japanese characters, so when I use the following code it substitutes '?' for each Japanese character and then cannot open the file.

CODE

Dim strFolder As String
Dim strFileSpec As String
Dim strFileName As String
Dim opres As Presentation

strFolder = Environ("USERPROFILE") & "\Desktop\Search\"
strFileSpec = "*.PP*"
strFileName = Dir$(strFolder & strFileSpec)

Set opres = Presentations.Open(FileName:=strFolder & strFileName, WithWindow:=False) 

How can I change this code to allow it to recognize Japanese (or any other special) characters in the file name?

Thanks,
Jeff

RE: VBA for PPT - Open PPT File using Presentations.Open with Japanese Characters in Filename

Work directly with the file object, not the name of the file.

CODE --> VBA

'Creating a FileSystemObject
Public FSO As New FileSystemObject
Sub ListFiles()
'Declaring variables
Dim objFolder As Folder
Dim objFile As File
Dim strPath As String

'Specify the path of the folder
strPath = "your\path\here"
'Create the object of this folder
Set objFolder = FSO.GetFolder(strPath)
'Check if the folder is empty or not
If objFolder.Files.Count = 0 Then
  MsgBox "No files were found...", vbExclamation
  Exit Sub
End If

'Loop through each file in the folder
For Each objFile In objFolder.Files
    If objFile.Type = "Microsoft PowerPoint Presentation" Then
        Presentations.Open (objFile)
    End If
Next

End Sub 

Must add the Microsoft Scripting Runtime reference.

Attribution:
Modified from https://www.exceltrick.com/formulas_macros/filesys...

RE: VBA for PPT - Open PPT File using Presentations.Open with Japanese Characters in Filename

(OP)
Thanks! That looks to have done the trick!

Jeff

RE: VBA for PPT - Open PPT File using Presentations.Open with Japanese Characters in Filename

Minor update to avoid problems trying to open temporary files created as files are opened and to handle different flavors of .PPT?

CODE --> VBA

CODE --> VBA
'Creating a FileSystemObject
Public FSO As New FileSystemObject
Sub ListFiles()
'Declaring variables
Dim objFolder As Folder
Dim objFile As File
Dim strPath As String

'Specify the path of the folder
strPath = "your\path\here"
'Create the object of this folder
Set objFolder = FSO.GetFolder(strPath)
'Check if the folder is empty or not
If objFolder.Files.Count = 0 Then
  MsgBox "No files were found...", vbExclamation
  Exit Sub
End If

'Loop through each file in the folder
For Each objFile In objFolder.Files
    If objFile.Type Like "Microsoft PowerPoint*" And Not objFile.Name Like "~$*" Then
        Presentations.Open (objFile)
    End If
Next

End Sub 

RE: VBA for PPT - Open PPT File using Presentations.Open with Japanese Characters in Filename

(OP)
Nice tweak!

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members!

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close