Excelmappen ansprechen
21.09.2005 07:32:39
Kerstin
den nachfolgenden Code hatte ich vor 3 tagen von Josef hier im Forum erhalten.
Er macht folgendes - sucht geöffnete Excelmappen mit den Namen mappe2 bis Mappe9 und führt Berechnungen durch. Funktioniert im Einzelfall super. Mein problem ist folgendes: Die Excelmappen werden durch eine Andere Anwendung kreiert und einzeln abgelegt. Sie werden nicht in einer Gruppe zusammengefasst, die man im Fenstermenü zusammen sehen könnte.
Wie schafft man es trotzdem, dass die mappen angesprochen werden. Die Namen Mappe2, Mappe3,....Mappe9 sind immer gleich.
Vielleicht hat jemand zur frühen Morgenstunde eine Idee
Danke Kerstin
Private Sub ChangeFiles()
Dim wkb As Workbook
Dim ws As Worksheet
Dim n As Integer
Dim lRow As Long
Dim blnRightName As Boolean
On Error GoTo ERREXIT
With Application
.EnableEvents = False
.ScreenUpdating = False
.DisplayAlerts = False
.Calculation = xlCalculationManual
End With
For Each wkb In Application.Workbooks
blnRightName = False
For n = 2 To 9
If wkb.Name = "Mappe" & n Then
blnRightName = True
Exit For
End If
Next
If blnRightName Then
For Each ws In wkb.Worksheets
lRow = ws.Range("C65536").End(xlUp).Row
If lRow < 5 Then lRow = 5
ws.Range(ws.Cells(5, 5), ws.Cells(lRow, 5)).FormulaR1C1 = "=RC[-2]/RC[-1]"
ws.Range(ws.Cells(5, 6), ws.Cells(lRow, 6)).FormulaR1C1 = "=RC[-4]*RC[-3]/RC[-2]"
ws.Calculate
ws.Range(ws.Cells(5, 5), ws.Cells(lRow, 5)) = ws.Range(ws.Cells(5, 5), ws.Cells(lRow, 5)).Value
ws.Range(ws.Cells(5, 6), ws.Cells(lRow, 6)) = ws.Range(ws.Cells(5, 6), ws.Cells(lRow, 6)).Value
Next
Set wkb = Nothing
End If
Next
ERREXIT:
If Err.Number > 0 Then
MsgBox Err.Description & vbLf & Err.Number, vbExclamation, "Fehler"
End If
With Application
.EnableEvents = True
.ScreenUpdating = True
.DisplayAlerts = True
.Calculation = xlCalculationAutomatic
End With
End Sub