Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

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

Status
Not open for further replies.

jmarkus

Technical User
Oct 15, 2002
124
CA
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
 
Work directly with the file object, not the name of the file.

Code:
'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
 
Thanks! That looks to have done the trick!

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

Code:
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 [COLOR=#CC0000]Like "Microsoft PowerPoint*"[/color] [COLOR=#8AE234]And Not objFile.Name Like "~$*"[/color] Then
        Presentations.Open (objFile)
    End If
Next

End Sub
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top