To horni bylo do ThisWorkbook
A tohle dat do List 1
Option Explicit
Dim MsgResponse
Private Sub CommandButton1_Click()
Dim CllF As Range, RwsF As Range, Rws As Range, OfsR As Long
Dim AWbk As Workbook, AWsht As Worksheet
Dim CestaSoubor As String, Lst As String, LastCll As Range
Dim RwsA As Range, OfsRA As Long
Set CllF = Range("f4")
Set RwsF = Range("a4:g4")
Set Rws = Rows(CllF.Row)
' archiv, list
CestaSoubor = "E:\Excel\Pom\Servis\ServisArchiv.xls"
Lst = "List1"
'otevrit archiv
Application.ScreenUpdating = False
If Not OpenWbkArchiv(AWbk, AWsht, CestaSoubor, Lst) Then _
Application.ScreenUpdating = True: Exit Sub
Set LastCll = AWsht.Cells(Rows.Count, "A").End(xlUp) ' posledni bunka v A:A archivu
Set RwsA = LastCll.Resize(1, 7).Offset(1, 0) ' prvni volny radek v archivu Axx:Gxx
OfsRA = 0 ' ofset pro archiv
OfsR = 0
Do While CllF.Offset(OfsR, 0).Value <> vbNullString
If CllF.Offset(OfsR, 1) <> vbNullString Then ' kdyz Gxx<>"" ulozit do archivu
RwsA.Offset(OfsRA, 0).Value = RwsF.Offset(OfsR, 0).Value
OfsRA = OfsRA + 1
CllF.Offset(OfsR, -1).Value = Date
CllF.Offset(OfsR, 1).Value = vbNullString
Rws.Offset(OfsR, 0).Hidden = True
End If
OfsR = OfsR + 1
Loop
AWbk.Close True ' zavrit archiv a ulozit zmeny
Application.ScreenUpdating = True
End Sub
Private Sub CheckBox1_Click()
Dim CllF As Range, Rws As Range, OfsR As Long
Set CllF = Range("f4")
Set Rws = Rows(CllF.Row)
OfsR = 0
Application.ScreenUpdating = False
Do While CllF.Offset(OfsR, 0).Value <> vbNullString
With Rws.Offset(OfsR, 0)
If CheckBox1.Value = False Then
'skryt
If .Hidden = False And CllF.Offset(OfsR, 0).Value > Date Then _
.Hidden = True
Else
'zobrazit vse
.Hidden = False
End If
End With
OfsR = OfsR + 1
Loop
Application.ScreenUpdating = True
End Sub
Function OpenWbkArchiv(ByRef Wbk As Workbook, ByRef Wsht As Worksheet, CestaSoubor As String, List As String) As Boolean
OpenWbkArchiv = False
On Error GoTo Err1
Set Wbk = Workbooks.Open(CestaSoubor)
On Error GoTo Err2
Set Wsht = Wbk.Worksheets(List)
On Error GoTo 0
OpenWbkArchiv = True: Exit Function
Err1:
MsgResponse = MsgBox("Soubor: " & CestaSoubor & " nelze nalézt," & vbCrLf _
& " zkontrolujte jeho název a umístìní v adresáøi!", vbOKOnly + vbCritical)
Exit Function
Err2:
MsgResponse = MsgBox("List: " & List & " v souboru: " & CestaSoubor & vbCrLf _
& " nelze nalézt, zkontrolujte jeho název!", vbOKOnly + vbCritical)
Wbk.Close
End Function
citovat