Reputation: 406
I know export worksheets as separate files has been asked before too. I checked those answers but I couldn't find solution for my problems, hence asked new question.
Code :
Private Sub cancel_button_Click()
Unload Me
End Sub
Private Sub export_button_Click()
Dim FileExtStr As String
Dim FileFormatNum As Long
Dim xWs As Worksheet
Dim xWb As Workbook
Dim FolderName As String
Application.ScreenUpdating = False
Set xWb = Application.ThisWorkbook
DateString = Format(Now, "yyyy-mm-dd hh-mm-ss")
FolderName = xWb.Path & "\" & xWb.Name & " " & DateString
MkDir FolderName
For Each xWs In xWb.Worksheets
xWs.Copy
If xlsx = True Then
FileExtStr = ".xlsx": FileFormatNum = 51
Unload Me
ElseIf xlsm = True Then
FileExtStr = ".xlsm": FileFormatNum = 52
Unload Me
ElseIf xls = True Then
FileExtStr = ".xls": FileFormatNum = 56
Unload Me
ElseIf xlsb = True Then
FileExtStr = ".xlsb": FileFormatNum = 50
Unload Me
End If
xFile = FolderName & "\" & Application.ActiveWorkbook.Sheets(1).Name & FileExtStr
Application.ActiveWorkbook.SaveAs xFile, FileFormat:=FileFormatNum
Application.ActiveWorkbook.Close False
Next
MsgBox "You can find the files in " & FolderName
Application.ScreenUpdating = True
End Sub
With above code and userform, I am able to work perfectly. I don't know the FileFormatNum for csv
and txt
, hence I could'nt create if loop for those two fileformat.
I need your help. I need to create a combobox in userform specifying around 15 fileformats. And also, a file browse button to select the export folder. User does both the selection(file format and location of folder for export).
I have created the userform:
How can I do it? I am not able to do it. Please anyone. Just give me a push and I'll finish it.
Upvotes: 0
Views: 321
Reputation: 183
FileFormatNum for csv and txt are here.
https://msdn.microsoft.com/en-us/VBA/Excel-VBA/articles/xlfileformat-enumeration-excel
For eaisly finding xlfileformat just Go to the object browser in the VB window (Press F2) and then type xlFileFormat in the Search Text box.
Upvotes: 1