Open file using first piece of file name

  • Thread starter Thread starter Josh
  • Start date Start date
J

Josh

I need to know what code to use in order to open a file based on the first 5
characters of the filename. How do you open a file based on the first 5
characters?
 
try first 5 characters*.* should find all files in a particular folder which
fit those parameters.

--
Michael Koerner
MS MVP - PowerPoint


I need to know what code to use in order to open a file based on the first 5
characters of the filename. How do you open a file based on the first 5
characters?
 
I need to know what code to use in order to open a file based on the first 5
characters of the filename. How do you open a file based on the first 5
characters?

Are you doing this in VBA or the like, Josh?

Can you explain what you're after in more detail?
 
Hey Josh,

I'm guessing you are trying to parse out the name for using elsewhere in a
VBA routine.

Try something like this....

Sub ToBeO()
Dim NewName As String


With ActivePresentation
If Left$(.Name, 12) = "Presentation" Then Exit Sub
NewName = Left$(.Name, 5) & "100" & ".txt"
End With
End Sub


The If statement is looking to see if the file is using the generic name (it
hasn't been saved with a name yet).

The string variable called NewName will have the same first 5 letters as the
presentation name followed by 100.txt. For Example, if we have a
presentation called MyPowerPoint.pptx, the sub will return the string
MyPow100.txt - Is this what you needed?

Bill Dilworth
 
Thank you for your response. What I need to do is use the file open code,
but I am going to loop through a list of state names and I need to open each
file in order. The only way to open each one up without having to use the
whole file name is to base the name on the first 5 characters of the file
name. I hope this helps.
 
Ohio & Utah might cause problems unless you pad them... Anyway ...

The file open routine varies depending on what type of file and what you
want to do with it. Is it a presentation, excel sheet, database, or a
simple text file? Do you want to run it, edit it, show it, or grab data
from it?

Bill Dilworth
 
I am actually looping through powerpoint presentation files. I want to open
the file, delete all images (I have another question posted related to that),
pop in the new images (I do have code for that), and then save the file under
a new name (I have code for that too).
 
Back
Top