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
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