Gruppe
Dialog
Problem
Die in einer UserForm-Listbox auszuwählenden Arbeitsblätter sind in einer neuen Arbeitsmappe zu speichern.
ClassModule: frmSheets
Private Sub cmdCancel_Click()
Unload Me
End Sub
Private Sub cmdOK_Click()
Dim arr() As String
Dim iRow As Integer, iCounter As Integer
Dim sPath As String
Application.ScreenUpdating = False
sPath = Application.DefaultFilePath & "\"
For iRow = 0 To lstSheets.ListCount - 1
If lstSheets.Selected(iRow) Then
iCounter = iCounter + 1
ReDim Preserve arr(1 To iCounter)
arr(iCounter) = Worksheets(lstSheets.List(iRow)).Name
End If
Next iRow
Worksheets(arr).Copy
Application.DisplayAlerts = False
ActiveWorkbook.SaveAs sPath & "test.xls"
Application.DisplayAlerts = True
ActiveWorkbook.Close savechanges:=False
Application.ScreenUpdating = True
Unload Me
End Sub
Private Sub UserForm_Initialize()
Dim wks As Worksheet
For Each wks In Worksheets
lstSheets.AddItem wks.Name
Next wks
End Sub
StandardModule: Modul1
Sub CallForm()
frmSheets.Show
End Sub