Hi,
ich dachte, wenn ich ein Sheet aktiviere und eine Zelle selektiere, dann wird sie auch angezeigt, das ist aber nicht so. Welcher Befehl fehlt noch?
Option Explicit
Private Sub Workbook_Open()
Dim i As Integer
With Sheets(strJahr)
.EnableSelection = xlUnlockedCells
i = .Cells(.Rows.Count, "B").End(xlUp).Row
.Activate
.Cells(i + 1, 2).Select
End With
End Sub
Und warum wird bei diesem Code trotzdem nachgefragt, ob ich speichern will, wenn ich die Datei schließe?
Private Sub Workbook_BeforeClose(Cancel As Boolean)
' strJahr = Year(Now)
Sheets(strJahr).Activate
If ThisWorkbook.Saved = False Then
Application.DisplayAlerts = False
ThisWorkbook.Save
Application.DisplayAlerts = True
End If
End Sub
Hi Ralf,
mir nicht verständlich, daß dein Code trotz Option Explicit nicht meckert.
Code:
Private Sub Workbook_Open()
Dim strJahr
Dim i
strJahr = "Tabelle1"
With Sheets(strJahr)
.EnableSelection = xlUnlockedCells
i = .Cells(.Rows.Count, "B").End(xlUp).Row
.Activate
.Cells(i + 1, 2).Select
End With
End Sub
So funktioniert es bei mir korrekt und die nächste leere Zelle in B wird aktiviert.
Hi Michael,
(25.05.2017, 10:38)Zwergel schrieb: [ -> ]mir nicht verständlich, daß dein Code trotz Option Explicit nicht meckert.
jetzt geht es bei mir plötzlich auch wieder. Excel meckert nicht, weil strJahr eine Public-Const im Modul "mdl_Variablen" ist.
Zum zweiten Makro:
Wenn ich auf das Close-Kreuz drücke, wird die Mappe gespeichert, dann fragt Excel aber nach, ob die Datei gespeichert werden soll und dann wird sie bei "Ja" oder "Nein" geschlossen.
Weitere Auffälligkeit: wenn ich
diese Datei aus einer
anderen Datei heraus (mit dem
dortigen Workbook_Open) öffne, wird in
dieser Datei das Workbook_Open (wie oben gezeigt) nicht beachtet.
Moin Ralf!
Zu Deiner zweiten Frage aus der Eröffnung:
Ich nehme so etwas, dann wird problemlos ohne Nachfrage gepeichert.
Code:
Private Sub Workbook_BeforeClose(Cancel As Boolean)
If Not Me.Saved Then Me.Save
End Sub
Gruß Ralf
Hi Ralf,
auch damit kommt bei mir eine Nachfrage.
I werd no narrisch! (österreichisch, weil ich grad 3sat Ö anschaue :) )
Wo könnte denn da noch was stehen, daß ein Speichern fordert?
Ohne Datei nur die Mutmaßung, dass noch etwas in DieseArbeitsmappe steht.
A pro pos Speichern:
Ich kümmere mit jetzt um =WECHSELN("Speichern";"r";"")
Heißt, ich werde jetzt die Speichen meines Fahrrads in Bewegung setzen. ;)
Gruß Ralf
Hallo Ralf,
(25.05.2017, 12:51)RPP63 schrieb: [ -> ]Ohne Datei nur die Mutmaßung, dass noch etwas in DieseArbeitsmappe steht.
Datei 1:
Microsoft Excel Objekt DieseArbeitsmappeOption Explicit
Private Sub Workbook_Open()
Dim Pfad As String
With Sheets(strWetter)
.EnableSelection = xlUnlockedCells
i = .Cells(.Rows.Count, "B").End(xlUp).Row
.Activate
.Cells(i + 1, 2).Select
End With
Application.ScreenUpdating = False
Pfad = ActiveWorkbook.Path
Workbooks.Open Pfad & "\Wetterdaten-Stunde.xlsb"
Application.ScreenUpdating = True
End Sub
Private Sub Workbook_BeforeClose(Cancel As Boolean)
With Sheets(strWetter)
.EnableSelection = xlUnlockedCells
.Activate
loLetzte = .Cells(Rows.Count, 2).End(xlUp).Row ' letzte belegte Zelle in Spalte B
Application.Goto .Cells(loLetzte, "B"), True ' anspringen der letzten belegten Zelle
End With
Application.ScreenUpdating = False
ThisWorkbook.Save
Application.ScreenUpdating = True
End Sub
Datei 2, durch 1 geöffnet:
Microsoft Excel Objekt DieseArbeitsmappeOption Explicit
Private Sub Workbook_Open()
With Sheets(strJahr)
.EnableSelection = xlUnlockedCells
i = .Cells(.Rows.Count, "B").End(xlUp).Row
.Activate
.Cells(i + 1, 2).Select
End With
End Sub
Private Sub Workbook_BeforeClose(Cancel As Boolean)
' strJahr = Year(Now)
' Sheets(strJahr).Activate
' If ThisWorkbook.Saved = False Then
' Application.DisplayAlerts = False
' ThisWorkbook.Save
' Application.DisplayAlerts = True
' End If
If Not Me.Saved Then Me.Save
End Sub
'Private Sub Workbook_SheetActivate(ByVal Sh As Object)
' With Sheets("Ertrag PV-Anlage")
' Call AllePivotTabellenaktualisieren
' End With
'End Sub
'
Hi,
(25.05.2017, 18:05)snb schrieb: [ -> ]Code:
Private Sub Workbook_Open()
Application.goto Sheets(year(date)).cells(rows.count,1).end(xlup)
End Sub
ja, so geht es auch! Das habe ich jetzt verwendet.