GetFileName Method

JerryGiese

Active Member
Joined
Jun 27, 2005
Messages
323
How do you use the GetFileName method in Word? It does not seem to the same as in excel?
 

Excel Facts

Using Function Arguments with nested formulas
If writing INDEX in Func. Arguments, type MATCH(. Use the mouse to click inside MATCH in the formula bar. Dialog switches to MATCH.
you can use thisworkbook.name
it'll also include the .xls like: file.xls

to get the filename without xls....erm I dunno...
 
Upvote 0
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:
Upvote 0
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
 
Upvote 0
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.
 
Upvote 0
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.
 
Upvote 0
From Excel VBA help file:

<TABLE id=topTable width="100%"><TBODY><TR id=headerTableRow2><TD align=left>GetFileName Method</TD></TR></TBODY></TABLE>
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:
<TABLE><TBODY><TR><TH>Part</TH><TH>Description</TH></TR><TR><TD>object</TD><TD>Required. Always the name of a FileSystemObject.</TD></TR><TR><TD>pathspec</TD><TD>Required. The path (absolute or relative) to a specific file.</TD></TR></TBODY></TABLE>
Remarks
The GetFileName method returns a zero-length string ("") if pathspec does not end with the named component.

<TABLE><TBODY><TR><TH>
default.aspx
Note</TH></TR><TR><TD>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.</TD></TR></TBODY></TABLE>
 
Upvote 0
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.
 
Upvote 0

Forum statistics

Threads
1,213,515
Messages
6,114,080
Members
448,548
Latest member
harryls

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top