×
INTELLIGENT WORK FORUMS
FOR ENGINEERING PROFESSIONALS

Log In

Come Join Us!

Are you an
Engineering professional?
Join Eng-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

*Eng-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

Macro Code Help

Macro Code Help

Macro Code Help

(OP)
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

RE: Macro Code Help

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.

RE: Macro Code Help

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).

RE: Macro Code Help

Wow, do I feel dumb.  Math has always been my strong point, too.

RE: Macro Code Help

(OP)
Thanks for the input guys! I can always count on this forum!

have a great weekend.

Todd

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 Eng-Tips Forums free from inappropriate posts.
The Eng-Tips staff will check this out and take appropriate action.

Reply To This Thread

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

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


Resources