'----------------
Public Sub ExportAllSheets2Name()
'----------------
Dim sht, vFile, vDir
vDir = getMyDocs()
For Each sht In Worksheets
'MsgBox sht.Name
vFile = UserFileSaveAs(vDir, sht.Name)
If vFile = "" Then Exit Sub
vDir = getDirName(vFile)
sht.Copy
ActiveWorkbook.SaveAs Filename:=vFile, FileFormat:=xlOpenXMLWorkbook, CreateBackup:=False
ActiveWorkbook.Close False
Next
End Sub
'----------------
Public Function UserFileSaveAs(ByVal pvPath, ByVal pvName)
'----------------
Dim strTable As String
Dim strFilePath As String
Dim sDialog As String, sDecr As String, sExt As String
'MUST ADD REFERENCE : Microsoft Office 11.0 Object Library
With Application.FileDialog(msoFileDialogSaveAs)
'With Application.FileDialog(msoFileDialogFilePicker)
.AllowMultiSelect = False
.Title = "Save sheet:" & UCase(pvName)
.ButtonName = "Save"
'.Filters.Clear
'.Filters.Add "All Files", "*.*"
.InitialFileName = pvPath
.InitialView = msoFileDialogViewList 'msoFileDialogViewThumbnail
''.AllowMultiSelect = True
If .Show = 0 Then
'There is a problem
Exit Function
End If
'Save the first file selected
UserFileSaveAs = Trim(.SelectedItems(1))
End With
End Function
'----------------
Public Function getMyDocs()
'----------------
Dim vDir, vUsr
On Error GoTo errDocs
vUsr = Environ("UserProfile")
vDir = vUsr & "\Documents\"
If Not DirExists(vDir) Then
vDir = vUsr & "\My Documents\"
If Not DirExists(vDir) Then
vDir = "c:\temp"
MakeDir vDir
End If
End If
getMyDocs = vDir
Exit Function
errDocs:
MsgBox "Cannot find temp folder", vbInformation, "getMyDocs():" & Err
End Function
'----------------
Public Function getDirName(ByVal psFilePath)
'----------------
Dim i As Integer, sDir As String
i = InStrRev(psFilePath, "\")
If i > 0 Then getDirName = Left(psFilePath, i)
End Function