Results 1 to 8 of 8
  1. #1
    3 Star Lounger
    Join Date
    Jan 2001
    Location
    Wellington, Wellington, New Zealand
    Posts
    378
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Determine extension of a file (Word97/NT)

    Hi

    I sometimes need to determine what the extension of a file is (for example, ".doc"), and do this rather longwindedly by finding the last "." in the filename.

    Is there a quicker way?

    Thanks
    Dale

  2. #2
    Silver Lounger
    Join Date
    Mar 2001
    Location
    Springfield, Ohio, USA
    Posts
    2,136
    Thanks
    0
    Thanked 1 Time in 1 Post

    Re: Determine extension of a file (Word97/NT)

    <img src=/w3timages/blackline.gif width=33% height=2>
    > do this rather longwindedly by finding the last "."
    <img src=/w3timages/blackline.gif width=33% height=2>
    The easiest thing is to just put that code into a subroutine, but it makes you feel like you are reinventing the wheel. If you are doing a lot of file operations, then you probably want to switch to using the FileSystemObject. You can search the Excel, Word, and VBA boards for examples, but you basically have three steps:
    1) Add a reference to MS Scripting Runtime via the Tools, References menu
    2) Create the object
    <pre> dim fso as New Scripting.FileSystemObject </pre>

    3) Use the method
    <pre> msgbox fso.GetExtensionName("c:Tempx.123") </pre>

    HTH --Sam
    <font face="Comic Sans MS">Sam Barrett, CACI </font face=comic>
    <small>And the things that you have heard... commit these to faithful men who will be able to teach others also. 2 Timothy 2:2</small>

  3. #3
    3 Star Lounger
    Join Date
    Jan 2001
    Location
    Wellington, Wellington, New Zealand
    Posts
    378
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Re: Determine extension of a file (Word97/NT)

    Thanks, Sam

    If a different person runs the macro, do they also have to set up the reference to "MS Scripting Runtime"?

    Dale

  4. #4
    Silver Lounger
    Join Date
    Mar 2001
    Location
    Springfield, Ohio, USA
    Posts
    2,136
    Thanks
    0
    Thanked 1 Time in 1 Post

    Re: Determine extension of a file (Word97/NT)

    The reference is saved as part of the workbook not as a part of your environment, so the macro will work for anyone who receives your workbook. However, if someone copies your code, then they would have to add the reference. --Sam
    <font face="Comic Sans MS">Sam Barrett, CACI </font face=comic>
    <small>And the things that you have heard... commit these to faithful men who will be able to teach others also. 2 Timothy 2:2</small>

  5. #5
    Gold Lounger
    Join Date
    Feb 2001
    Location
    Dublin, Ireland, Republic of
    Posts
    2,697
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Re: Determine extension of a file (Word97/NT)

    If you save the document with the reference set it should work unless the other system does not have the file scrrun.dll. However it should be on all systems with Windows 98 or later installed OR Internet Explorer 5.0 or later.

    Andrew C

  6. #6
    Plutonium Lounger
    Join Date
    Dec 2000
    Location
    Sacramento, California, USA
    Posts
    16,775
    Thanks
    0
    Thanked 1 Time in 1 Post

    Re: Determine extension of a file (Word97/NT)

    ... Unless the system administrator has disabled or removed it for security reasons.
    Charlotte

  7. #7
    3 Star Lounger
    Join Date
    Jan 2001
    Location
    Wellington, Wellington, New Zealand
    Posts
    378
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Re: Determine extension of a file (Word97/NT)

    Thanks, Andrew

    I've got it working under Word97/NT. However, my standalone Windows 98 PC (with IE5) doesn't have scrrun.dll. It shows up in the Tools|References list, but the DLL isn't on the hard drive.

    Does this sound right? Any ideas where I can get it from?

    Added later
    Oops. Something weird going on here. Now it's there.

    This is what I did (I think):
    <UL><LI>Tools|References, selected MS Scripting Runtime, clicked OK.
    <LI>Ran macro. Failed.
    <LI>Tools|References again. MS Scripting Runtime not selected.
    <LI>Tried a couple more times. Wouldn't stick.
    <LI>Searched from c: for scrrun.dll (all folders). Not there.
    <LI>Back to VB for Word editor to check the DLL's name. Decided to try one more time.
    <LI>Worked.[/list]Is this possible, or am I going through one of my blue periods again?


    Thanks
    Dale

  8. #8
    Gold Lounger
    Join Date
    Feb 2001
    Location
    Dublin, Ireland, Republic of
    Posts
    2,697
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Re: Determine extension of a file (Word97/NT)

    Cannot really say what happened to you.

    Look at <A target="_blank" HREF=http://www.wopr.com/cgi-bin/w3t/showthreaded.pl?Cat=&Board=xl&Number=99034&Search= true&Forum=All_Forums&Words=scrrun.dll&Match=And&S earchpage=0&Limit=25&Old=allposts&Main=98746>This Post</A> if you want to install scrrun.dll on a PC.

    Regards,

    Andrew C

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •