Trying to create a userform with two options buttons for saving the activeworkbook in either xlsx, or xlsb format. Where the option button names are SS: .for saving in xlsb;NS: for saving in .xlsx, in the code below.
Run-time error 1004: Method "SaveAs" of object "_Workbook" failed
I have highlighted the code in red to where the debugger points towards. Funny enough, it manages to save it in .xlsx format just fine.
Dim sPath As String
Dim GetTheName As String
Dim Form1 As Variant, Form2 As Variant
Dim add_ext1 As String, add_ext2 As String
Dim wb As Workbook
____________________________________________________________________
Private Sub CancelButton_Click()
Unload Me 'me = userform
End Sub
____________________________________________________________________
Private Sub GetFilePath_Click()
GetTheName = FileNameTextBox.Value
With Application.FileDialog(msoFileDialogFolderPicker)
.ButtonName = "Save in this folder"
If .Show = -1 Then 'if ok is pressed
sPath = .SelectedItems(1)
End If
End With
Set wb = ActiveWorkbook
todaysDay = Format(Now(), "dd.mm.yyyy")
If sPath <> "" Then
If NS = True Then
wb.SaveAs Filename:=sPath & "\" & GetTheName & " " & Format(Now(), "dd.mm.yyyy") & ".xlsx", FileFormat:=Form1
ElseIf SS = True Then
wb.SaveAs Filename:=sPath & "\" & GetTheName & " " & Format(Now(), "dd.mm.yyyy") & ".xlsb", FileFormat:=Form2
End If
End If
Unload Me
End Sub
____________________________________________________________________
Private Sub NS_Click()
Form1 = xlWorkbookDefault
End Sub
____________________________________________________________________
Private Sub SS_Click()
Form2 = xlExcel12
End Sub
Bookmarks