How do I get the current filename of a Word document, without the extension or full path, using a macro?

FSO has a set of methods for this type of thing, one of which is "getBaseName"

Msgbox CreateObject("scripting.filesystemobject").getbasename(o.Name)

http://msdn.microsoft.com/en-us/library/xhxzwwe1(v=vs.84).aspx


Sub ShowFilename()
Dim pathName As String
Dim o As Document
Set o = ActiveDocument
If InStrRev(o.Name, ".") <> 0 Then
    MsgBox Left(o.Name, InStrRev(o.Name, ".") - 1)
Else
    MsgBox o.Name
End If
End Sub

I initially posted this without the if, which would error if the file had never been saved, or had no extension.

Tags:

Ms Word

Vba