1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38
|
Dim FileExtStr As String
Dim FileFormatNum As Long
Dim Destwb As Workbook
Dim TempFilePath As String
Dim TempFileName As String
Set Destwb = ActiveWorkbook
With Destwb
If Val(Application.Version) < 12 Then
'You use Excel 97-2003
FileExtStr = ".xls": FileFormatNum = -4143
Else
'You use Excel 2007-2013
Select Case Destwb.FileFormat
Case 51: FileExtStr = ".xlsx": FileFormatNum = 51
Case 52:
If .HasVBProject Then
FileExtStr = ".xlsm": FileFormatNum = 52
Else
FileExtStr = ".xlsx": FileFormatNum = 51
End If
Case 56: FileExtStr = ".xls": FileFormatNum = 56
Case Else: FileExtStr = ".xlsb": FileFormatNum = 50
End Select
End If
End With
TempFilePath = ActiveWorkbook.Path & "\"
TempFileName = CreateObject("Scripting.FileSystemObject").GetBaseName(ActiveWorkbook.Name)
With Destwb
.SaveAs TempFilePath & TempFileName & FileExtStr, FileFormat:=FileFormatNum, Password:="", WriteResPassword:="", ReadOnlyRecommended:=False, CreateBackup:=False
End With
MsgBox (TempFileName & FileExtStr & " a été sauvé dans : " & TempFilePath) |
Partager