Public Type BROWSfromFO
hOwner As Long
pidlRoot As Long
pszDisplayName As String
lpszTitle As String
ulFlags As Long
lpfn As Long
lParam As Long
iImage As Long
End Type
Declare Function SHGetPathFromIDList Lib "shell32.dll" _
Alias "SHGetPathFromIDListA" (ByVal pidl As Long, ByVal pszPath As String) As Long
Declare Function SHBrowseForFolder Lib "shell32.dll" _
Alias "SHBrowseForFolderA" (lpBrowsfromfo As BROWSfromFO) As Long
Function GetDirectory(Optional Msg As String) As String
Dim bInfo As BROWSfromFO
Dim Path As String
Dim r As Long, x As Long, pos As Integer
bInfo.pidlRoot = 0&
bInfo.lpszTitle = "Select your destination path:"
bInfo.ulFlags = &H1
x = SHBrowseForFolder(bInfo)
Path = Space$(512)
r = SHGetPathFromIDList(ByVal x, ByVal Path)
If r Then
pos = InStr(Path, Chr$(0))
GetDirectory = Left(Path, pos - 1)
Else
GetDirectory = ""
End If
End Function
Sub KoppySheetz()
Dim strDir As String
strDir = GetDirectory
If strDir = "" Then
MsgBox "You did not select a destination path.", 48, "Cancelled"
Exit Sub
End If
If Left(strDir, 1) <> "\" Then strDir = strDir & "\"
With Application
.ScreenUpdating = False
.DisplayAlerts = False
Dim ws As Worksheet, strSheetName$
For Each ws In Worksheets
strSheetName = ws.Name
Workbooks.Add 1
ws.Cells.Copy Cells
Sheets(1).Name = strSheetName
ActiveWorkbook.SaveAs strDir & strSheetName & ".xls"
ActiveWorkbook.Close 0
Next
.DisplayAlerts = True
.ScreenUpdating = True
End With
MsgBox "Your sheets are individually saved in the path" & vbCrLf & _
strDir, 64, "Done"
End Sub