Results 1 to 8 of 8

GetFileName Method

This is a discussion on GetFileName Method within the Excel Questions forums, part of the Question Forums category; How do you use the GetFileName method in Word? It does not seem to the same as in excel?...

  1. #1
    Board Regular
    Join Date
    Jun 2005
    Posts
    323

    Default GetFileName Method

    How do you use the GetFileName method in Word? It does not seem to the same as in excel?

  2. #2
    Board Regular
    Join Date
    Jul 2008
    Posts
    147

    Default Re: GetFileName Method

    you can use thisworkbook.name
    it'll also include the .xls like: file.xls

    to get the filename without xls....erm I dunno...
    Life is not about the destination but the journey...
    Enjoy it!

  3. #3
    New Member
    Join Date
    Aug 2008
    Posts
    1

    Default Re: GetFileName Method

    Just go to the file>open> and select the file you want. You are right that word isn't the same thing as excel. With MS excel, its main purpose if for spreadsheet(ie....formulas and tabulations)......with MS Word, its used for typing and general word processing. There are some other complicated ways of doing it, but they are tricky and you don't need to worry about things you don't need to be worrying about.
    Last edited by SheerDarson; Aug 6th, 2008 at 04:03 PM.

  4. #4
    Board Regular
    Join Date
    Jul 2008
    Posts
    51

    Default Re: GetFileName Method

    Documents have the property Name and FullName. FullName includes the path, while Name does not. Can you use that instead? e.g. ThisDocument.Name or ThisDocument.FullName

  5. #5
    Board Regular
    Join Date
    Jul 2008
    Posts
    51

    Default Re: GetFileName Method

    Nevermind. After looking into it you are probably doing something a bit different.

    Make sure to add a reference to Microsoft Scripting Runtime in the VBE.

    Then:
    Code:
        Dim fso As New FileSystemObject
     
        MsgBox fso.GetFileName("C:\Whatever\test.doc")
        MsgBox fso.GetBaseName("C:\Whatever\test.doc")
    If you've gotten it to work in Excel but not Word, you probably just need to make sure the reference is checked.

  6. #6
    Board Regular Kenneth Hobson's Avatar
    Join Date
    Feb 2007
    Location
    Tecumseh, OK
    Posts
    1,664

    Default Re: GetFileName Method

    Your goal is not clear.

    Since this is an Excel forum, not sure how this relates to Excel.

    Where is the GetFileName method in Excel? Maybe you meant GetOpenFileName? If so and you are using a newer version, use FileDialog.

  7. #7
    MrExcel MVP
    Moderator
    Scott Huish's Avatar
    Join Date
    Mar 2004
    Location
    Oregon
    Posts
    17,074

    Default Re: GetFileName Method

    From Excel VBA help file:

    GetFileName Method

    Description
    Returns the last component of specified path that is not part of the drive specification.
    Syntax
    object.GetFileName(pathspec)
    The GetFileName method syntax has these parts:
    PartDescription
    objectRequired. Always the name of a FileSystemObject.
    pathspecRequired. The path (absolute or relative) to a specific file.

    Remarks
    The GetFileName method returns a zero-length string ("") if pathspec does not end with the named component.

    Note
    The GetFileName method works only on the provided path string. It does not attempt to resolve the path, nor does it check for the existence of the specified path.
    Office 2007/2010

  8. #8
    Board Regular Kenneth Hobson's Avatar
    Join Date
    Feb 2007
    Location
    Tecumseh, OK
    Posts
    1,664

    Default Re: GetFileName Method

    Good guess Hotpepper. Obviously, it will work fine in MSWord if that is the case as fso is not exclusive to MSOffice applications. Another conjecture as to why he might of had problems using the fso method, is the use of an early binding method. He probably forgot to add the reference.

    Unless Jerry posts back, I have no further comment.

Like this thread? Share it with others

Like this thread? Share it with others

Posting Permissions

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


DMCA.com