ich möchte nach dem Ablauf meines Makros nur bestimmte Excelfenster, nämlich alle ausser Angebotspreis_berechnung.xls schließen!
Wer kann mir einen Tipp geben?
Mein Makro startet mit einem Dialogfenster wo der User die Exceldateien auswählt die er benötigt
Sub FileDialog()
'Declare a variable as a FileDialog object.
Dim fd As FileDialog
'Create a FileDialog object as a File Picker dialog box.
Set fd = Application.FileDialog(msoFileDialogFilePicker)
'Declare a variable to contain the path
'of each selected item. Even though the path is a String,
'the variable must be a Variant because For Each...Next
'routines only work with Variants and Objects.
Dim vrtSelectedItem As Variant
'Use a With...End With block to reference the FileDialog object.
With fd
'Use the Show method to display the File Picker dialog box and return the user's action.
'The user pressed the action button.
If .Show = -1 Then
'Wähle in der Datei Angebotspreis die Zelle B3 aus, hier wird später der erste Preis
'hinkopiert
Workbooks("Angebotspreis_berechnung.xls").Activate
Worksheets(1).Range("B3").Select
'Step through each string in the FileDialogSelectedItems collection.
For Each vrtSelectedItem In .SelectedItems
'vrtSelectedItem is a String that contains the path of each selected item.
'You can use any file I/O functions that you want to work with this path.
'This example simply displays the path in a message box.
'MsgBox "The path is: " & vrtSelectedItem
Call open_sheets2(vrtSelectedItem)
Next vrtSelectedItem
'The user pressed Cancel.
Else
End If
End With
'Set the object variable to Nothing.
Set fd = Nothing
End Sub
Anschliessend geht es wie folgt weiter:
'öffne Dateipfad welcher von modFileDialog übergeben wurde
Sub open_sheets2(ByVal SelectedFile As String)
Workbooks.Open Filename:=SelectedFile
'Aktiviere Tabellenblatt 1 (für den Fall das der User vorher bereits ein anderes Datenblatt
'ausgewählt hat
Worksheets(1).Activate
'Finde die Zeile in welcher der Gesamtpreis steht (steht je nach Anzahl der Komponenten in einer
'anderen Zeile
'Gehe in Zelle A1
Worksheets(1).Range("A1").Select
'Gehe jeweils eine Zelle nach unten, bis zur gewünschten Zelle Gesamtpreis
Do
ActiveCell.Range("A2").Activate
Loop Until ActiveCell.Value = "Gesamtpreis"
'Schreibe die gefundene Zeilenadresse in eine Variable
Dim Rowadress As String
Rowadress = ActiveCell.Address
'Gehe in die Spalte H zum TC
ActiveCell.Range("H1").Activate
'Kopiere Inhalt
ActiveCell.Copy
'Filename
Dim Filename As String
Filename = ActiveWorkbook.Name
Workbooks("Angebotspreis_berechnung.xls").Activate
Worksheets(1).Activate
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
ActiveCell.Offset(-1, 0).Activate
ActiveCell.Value = Filename
ActiveCell.Range("B2").Activate
Worksheets(1).Columns("A:I").AutoFit
End Sub
Wie könnte der Befehl aussehen den ich brauche?
Vielen Dank
Gruss
Jason