již nekolikátý den se mořím s následující:
Mám datové připojení pomocí Quary do SQL db. Po aktualizaci připojení, tj, tabulky v xls, potřebuji spustit makro.
Nechci použít OnTime, protože, si nejsem naprosto jist její spolehlivosti v kombinaci s datovým připojením a aktualizací dat na pozadí.
Na všech možných fórech jsem našel řešení QuaryTable_AfterRefresh. Kód přikládám. Bohužel, se mě tato záležitost nepodařila rozchodit.
Podle mě je problém v tom, že datové připojení na SQLdb nevrací QuaryTable objekt, ale ListObject objekt. Bohužel se mě to nedaří překonat.
toto jsem vložil do Class
Kód: Vybrat vše
Public WithEvents qt As QueryTable
Private Sub qt_BeforeRefresh(Cancel As Boolean)
Dim a As Integer
Dim My_Prompt As String
 My_Prompt = "Data will be refreshed."                               ' Initialize prompt text for message box.
 a = MsgBox("Do you want to refresh the data now?", vbYesNoCancel)   ' Get YES or NO result from the message box
  
   If a = vbNo Then                                                  ' Check to see wheather YES or NO was selected.
        My_Prompt = "Data will not be refreshed."       ' Change prompt text for message box.
        Cancel = True                                   ' Cancels the Query Refresh.
    End If
   MsgBox My_Prompt                                      ' Displays message box before refresh (or non-refresh) occurs.
End Subtento kód jsem vložil do modulu
Kód: Vybrat vše
  Dim X As New Class1
      Sub Initialize_It2()
        Set X.qt = ThisWorkbook.Sheets(2).ListObjects(1).QueryTable
      End SubTento kód je nabízen Microsoftem a různé mutace se objevují i na webu.








