Get File Name with out extension

O

Orasha

Hi,

I am new to Visual Basics. I am trying to write a macro to read the
finename with out the extension and minipulate resave the filenme.

Public Function FileNameWithoutExtension(ByVal filename _
As String) As String

Set filename = path.GetFileNameWithoutExtension(Active.Document)


End Function
Sub Test()

Dim filename As String
Dim pathName As String
Dim strOldName As String
Dim strSuffix
Dim messageBoxText As String

With ActiveDocument
If Len(.path) = 0 Then 'No path means document not saved
.Save 'So save it
End If

pathName = ActiveDocument.path 'Get path
MsgBox (pathName)
filename = ActiveDocument.Name 'Get document name
MsgBox (filename)
End With

StrOldName = path.GetFileNameWithoutExtension(filename) 'get runtime error
424 here

MsgBox (strOldName)

End Sub


Whats the best was to handle file with "." in the file name eg
myfile_v1.5.docx?

Thanks
Orasha
 
G

Graham Mayor

Dim pPathname As String
With ActiveDocument
If Len(.Path) = 0 Then
.Save
End If
If Right(.name, 1) = "x" Then
pPathname = Left$(.FullName, (Len(.FullName) - 5))
Else
pPathname = Left$(.FullName, (Len(.FullName) - 4))
End If
End With
MsgBox pPathname


--
<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
Graham Mayor - Word MVP


<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top