AW: Tabellenblatt automatisch in Ordner abspeichern
18.04.2018 11:06:07
EtoPHG
Hallo Namenloser,
Probier mal (unter der Annahme, dass die Sub-Verzeichnisse unter dem Verzeichnis liegen, in dem die Arbeitsmappe abgespeichert ist) :
Option Explicit
' Diesen Code in ein Standardmodul
Declare Function MakeSureDirectoryPathExists Lib "imagehlp.dll" (ByVal Pfad As String) As Long
' GetMoreSpeed
Sub GetMoreSpeed(Optional ByVal Modus As Boolean = True)
Static intCalculation As Integer
If Modus = True Then intCalculation = Application.Calculation
With Application
.ScreenUpdating = Not Modus
.EnableEvents = Not Modus
.Calculation = IIf(Modus = True, xlManual, intCalculation)
.Cursor = IIf(Modus = True, 2, -4143)
End With
End Sub
und dann noch so:
Option Explicit
' Diesen Code in das zu kopierende Tabellenblatt mit dem
' ActiveX Steuerelement CommandButton
Private Sub CommandButton1_Click()
Dim sWBName As String
Dim SubPathName As String
Dim NewWBName As String
GetMoreSpeed True
SubPathName = "\" & Format(Cells(2, 1), "MMMM YYYY") & "\"
NewWBName = Me.Name & "_" & Cells(2, 1).Text & ".xlsx"
UsedRange.Copy
MakeSureDirectoryPathExists (ThisWorkbook.Path & SubPathName)
Workbooks.Add
With ActiveWorkbook
With .Worksheets(1)
.Name = Me.Name
.Cells(1, 1).PasteSpecial Paste:=xlPasteValuesAndNumberFormats
.Cells(1, 1).PasteSpecial Paste:=xlPasteFormats
.Cells(1, 1).PasteSpecial Paste:=xlPasteColumnWidths
End With
Application.DisplayAlerts = False
Do While .Worksheets.Count > 1
.Worksheets(2).Delete
Loop
Application.DisplayAlerts = True
sWBName = ThisWorkbook.Path & SubPathName & NewWBName
.SaveAs sWBName
.Close
End With
Application.CutCopyMode = False
MsgBox "Daten gespeichert unter" & vbCrLf & _
sWBName, vbOKOnly + vbInformation
GetMoreSpeed False
End Sub
Gruess Hansueli