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 Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Path or Macro Name

Status
Not open for further replies.

remy988

Technical User
Mar 29, 2012
128
US
hi,

i have a macro stored in a particular directory. when i run the macro,
(1) is there a way to return the name of the macro? - or -
(2) is there a way to return the path where the macro is stored?


thanks
rem
 
Assuming you are doing this using VBA from like Excel (yes, assuming...we all know that's bad!)...try utilizing something along the lines of:
Splitting up a filename
The two examples in this section make it easy to extract a path or a filename from a full filespec, such as "c:\files\workbooks\archives\budget98.xls"

Function ExtractFileName(filespec) As String
' Returns a filename from a filespec
Dim x As Variant
x = Split(filespec, Application.PathSeparator)
ExtractFileName = x(UBound(x))
End Function

Function ExtractPathName(filespec) As String
' Returns the path from a filespec
Dim x As Variant
x = Split(filespec, Application.PathSeparator)
ReDim Preserve x(0 To UBound(x) - 1)
ExtractPathName = Join(x, Application.PathSeparator) & _
Application.PathSeparator
End FunctionUsing the filespec shown above as the argument, ExtractFileName returns "budget98.xls" and ExtractPathName returns "c:\files\workbooks\archives\"

It appears we aren't allowed to put direct links into post and I don't want to break the rules, but if you Google for "The Spreadhseet Page" and specifically for "The Versatile Split Function" you should be able to find the original resource quoted above.
This is all assuming you are working with an Excel macro that is opening and using an Attachmate session.
If not, just ignore me. [spin2]

If you bring that sentence in for a fitting, I can have it shortened by Wednesday!
 
hi DwMcC,

thanks for your thoughts on this. unfortunately, i had to code this in Extra, not VBA. it would have been a breeze with VBA.


rem
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top