Eng-Tips is the largest engineering community on the Internet

Intelligent Work Forums for Engineering Professionals

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

Macro Code Help

Status
Not open for further replies.

tbeck11

Mechanical
Dec 7, 2001
43
0
0
US
If I use the code below to strip off the last 6 characters of a file name, what code would I use to capture and store the first two characters of the file name?

filename = Strings.Left(filename, Len(filename) - 6) & "PDF"

My goal is to capture and store the first to characters and then us those characters to set the dir to save a file into.

Thanks.

Todd
 
Replies continue below

Recommended for you

FileName = Strings.Left(FileName, (Len(FileName) - (Len(FileName) - 2)))

This will return the first two characters of the string "FileName"

There is probably an easier way to do it, but it works.
 
Strings.Left(FileName, n)

This just takes the first n characters from the left side of FileName. So if you want to retrieve the first two letters of FileName, use

Strings.Left(FileName, 2)

Strings.Left(FileName, (Len(FileName) - (Len(FileName) - 2))) will work, too. However, if you look closely it's really saying Strings.Left(FileName, x - (x - 2)). x - (x - 2) = 2, so you're back to Strings.Left(FileName, 2).
 
Status
Not open for further replies.
Back
Top