Capturing part of text string (substring)

G

Glen Mettler

I want to capture and then change the extension of a file name. For
example, I have a project "MyProject.mpp"
I want to update the project using a CSV file and predefined map. The CSV
file is the same prefix name MyProject.CSV
In my code I have:
sub UpDateWithCSV()
MyPath = Application.ActiveProject.Path
MyFile = Application.ActiveProject.name


MyCSV = the prefix from MyFile with the suffix of ".csv"

OutlineShowAllTasks
FileOpen Name:=MyPath, ReadoOnly:=False, Merge:=1,
FormatID:="MyProject.csv", map:="MyMap"

End Sub
Note that the FormatID is hard coded with the csv file name. I want to
substitute that with MyCSV.

What I don't know how to do is to capture the prefix of MyFile and
substitute ".csv"

Anybody know how to do this?

TIA
Glen
 
J

John

Glen,
Unless I'm missing something this should work.
MyCSV = Mid(MyFile, 1, InStr(1, MyFile, ".") - 1) & ".csv"

This assumes you do NOT have your system set to hide extensions for
known file types. If you do then the ".mpp" (hence the ".") will not be
present in "MyFile". In that case the code is simply,
MyCSV = MyFile & ".csv"

John
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top