Gruppe
Datei
Bereich
Speichern
Thema
Sicherheitskopien von Arbeitsmappen speichern
Problem
Wie kann ich Sicherheitskopien von Arbeitsmappen anlegen, nachdem ich vorher über InputBox abgefragt habe, welche Arbeitsmappen gespeichert werden sollen?
Lösung
Geben Sie den nachfolgenden Code in ein Standardmodul ein und weisen Sie ihn einer Schaltfläche zu.
StandardModule: basMain
Sub Speichern()
Dim wkb As Workbook
Dim sSave As String, sFile As String
Dim sOld As String, sPath As String
sSave = InputBox("Backup für ""alle"" oder " & _
"""aktive"" Arbeitsmappe(n)?", , "aktive")
If sSave = "" Then Exit Sub
sPath = Range("B1").Value
If sSave = "alle" Then
For Each wkb In Workbooks
sFile = wkb.Name
sPath = wkb.FullName
wkb.SaveAs Range("B1").Value & sFile
wkb.SaveAs sPath
Next wkb
Else
Set wkb = ActiveWorkbook
sPath = wkb.FullName
wkb.SaveAs Range("B1").Value & ActiveWorkbook.Name
wkb.SaveAs sPath
End If
End Sub