|
Данный пример очень прост, поэтому особых пояснений не нужно. Function ChangeFileExtension(FileName As String, Extension As String, Optional
AddIfMissing As Boolean) As String
Dim i As Long
For i = Len(FileName) To 1 Step -1
Select Case Mid$(FileName, i, 1)
Case "."
ChangeFileExtension = Left$(FileName, i) & Extension
Exit Function
Case ":", "\"
Exit For
End Select
Next
If AddIfMissing Then
ChangeFileExtension = FileName & "." & Extension
Else
ChangeFileExtension = FileName
End If
End Function
Private Sub Command1_Click()
MsgBox ChangeFileExtension("ggg.htm", "txt")
MsgBox ChangeFileExtension("ggg", "txt", True)
End Sub
|
|