Vba excel событие tableupdate

The TableUpdate event occurs after a query table connected to a data model is updated. Excel uses the Worksheet_TableUpdate event procedure to trap the TableUpdate event. The Worksheet_TableUpdate procedure accepts Target (the TableObject) as the parameter which represents the table that was updated.

Creating a data model

You can make a data model by retrieving the data from a file, web, table, database or from any other source listed in the Data > Get Data as shown in the following image:

Get data menu from the Data tab

In our example, we’ll retrieve the data from a file. Create a text file and insert some data into it. For example, I have entered the following data into a blank text file and saved it as data.txt using notepad:

a,b,c
1,5,18
10,12,16
12,15,1
1,2,10

Back to Excel, Click Data tab and select From Text/CSV from the Get & Transform Data section to import the data from the data.txt file:

Import data from text or csv

Select data.txt file:

Select file to import

The next window shows the preview of data in a table form. Click Load To... button from the window as shown below image:

Data preview

Select the Add this data to the Data Model and click ok:

Another dialog box to create data model

Data will show on a new Worksheet and a query (data) will also made which visible on the left side of the sheet under the Queries & Connection:

Queries and Connections

If the data in the data.txt file changes, the changes will not be automatically updated on the table. To update the changes click Data tab and click Refresh All menu from the Queries & Connections section:

Click Refresh All to update data

The TableUpdate event occurs after a query table connected to a data model is updated. The Worksheet_TableUpdate procedures must be in the code module for that worksheet. You can quickly access that code window by right-clicking the worksheet’s tab and selecting the View Code:

View code context menu

In our data-model, the data imported to new sheet, Sheet2. Right-click on the Sheet2 tab, select View Code and write the following code.

Private Sub Worksheet_TableUpdate(ByVal Target As TableObject)
 MsgBox "Data from the data.txt has been updated"
End Sub

Back to Sheet2 and click Data tab and click Refresh All menu from the Queries & Connections section, it will reload (update) the data from the data.txt file and Excel fires the TableUpdate event which executes the Worksheet_TableUpdate event procedure:

The TableUpdate procedure executed

by updated May 07, 2020

This repository has been archived by the owner on Aug 31, 2018. It is now read-only.

Permalink

Cannot retrieve contributors at this time

title keywords f1_keywords ms.prod ms.assetid ms.date

Worksheet.TableUpdate Event (Excel)

vbaxl10.chm502088

vbaxl10.chm502088

excel

69610de6-6884-d5f5-449d-ec1d766d530d

06/08/2017

Worksheet.TableUpdate Event (Excel)

Occurs after a Query table connected to the Data Model is updated on a worksheet.

Syntax

expression . TableUpdate(Target)

expression A variable that represents a Worksheet object.

Parameters

Name Required/Optional Data type Description
Target Required TABLEOBJECT The Query table with data from the Data Model.

See also

Concepts

Worksheet Object

  • Remove From My Forums
  • Question

  • Trying to use the Worksheet.TableUpdate event in VBA with the following syntax…

    «Private Sub Worksheet_TableUpdate(ByVal Target As TableObject)»

    but the sub is not triggered when I refresh the only PowerQuery query in the document. The code is on the Sheet1 module as there’s only 1 sheet in the workbook. 

    What’s the correct syntax for this event? And could you provide a working example (i.e. one that you’ve tested)?

    • Moved by

      Wednesday, September 21, 2016 6:35 AM
      Move Case

Answers

    • Proposed as answer by
      Chenchen Li
      Sunday, September 25, 2016 1:11 PM
    • Marked as answer by
      Chenchen Li
      Friday, September 30, 2016 5:19 AM

Это не то событие
Примерно так

‘ by ZVI https://www.planetaexcel.ru/forum/index.php?PAGE_NAME=profile_view&UID=127
Dim WithEvents q As QueryTable

Private Sub q_AfterRefresh(ByVal Success As Boolean)
Debug.Print «AfterRefresh», Now
End Sub

Private Sub q_BeforeRefresh(Cancel As Boolean)
Debug.Print «BeforeRefresh», Now
End Sub

Private Sub Workbook_Open()
Application.OnTime Now, Me.Name & «.Start»
End Sub

Sub Start()
Set q = Sheet2.QueryTables(1)
End Sub

Это не то событие
Примерно так

‘ by ZVI https://www.planetaexcel.ru/forum/index.php?PAGE_NAME=profile_view&UID=127
Dim WithEvents q As QueryTable

Private Sub q_AfterRefresh(ByVal Success As Boolean)
Debug.Print «AfterRefresh», Now
End Sub

Private Sub q_BeforeRefresh(Cancel As Boolean)
Debug.Print «BeforeRefresh», Now
End Sub

Private Sub Workbook_Open()
Application.OnTime Now, Me.Name & «.Start»
End Sub

Sub Start()
Set q = Sheet2.QueryTables(1)
End Sub

Замечательный Временно просто медведь , процентов на 20.

Сообщение Это не то событие
Примерно так

‘ by ZVI https://www.planetaexcel.ru/forum/index.php?PAGE_NAME=profile_view&UID=127
Dim WithEvents q As QueryTable

Private Sub q_AfterRefresh(ByVal Success As Boolean)
Debug.Print «AfterRefresh», Now
End Sub

Private Sub q_BeforeRefresh(Cancel As Boolean)
Debug.Print «BeforeRefresh», Now
End Sub

Private Sub Workbook_Open()
Application.OnTime Now, Me.Name & «.Start»
End Sub

Sub Start()
Set q = Sheet2.QueryTables(1)
End Sub

Источник

Vba excel событие tableupdate

This forum has migrated to Microsoft Q&A. Visit Microsoft Q&A to post new questions.

Answered by:

Question

Trying to use the Worksheet.TableUpdate event in VBA with the following syntax.

«Private Sub Worksheet_TableUpdate(ByVal Target As TableObject)»

but the sub is not triggered when I refresh the only PowerQuery query in the document. The code is on the Sheet1 module as there’s only 1 sheet in the workbook.

What’s the correct syntax for this event? And could you provide a working example (i.e. one that you’ve tested)?

  • Moved by Emi Zhang Microsoft contingent staff Wednesday, September 21, 2016 6:35 AM Move Case

Answers

The event occurs after a Query table connected to the Data Model is updated on a worksheet.

Following Create a Data Model in Excel , I am adding data from Access and importing a Table.

Make sure «Add this data to the Data Model» checked.

The event fires after Importing and Refreshing.

All replies

This is the forum to discuss questions and feedback for Microsoft Excel, I’ll move your question to the MSDN forum for Excel

The reason why we recommend posting appropriately is you will get the most qualified pool of respondents, and other partners who read the forums regularly can either share their knowledge or learn from your interaction with us. Thank you for your understanding.

Regards,
Emi Zhang
TechNet Community Support

Источник

Vba excel событие tableupdate

Question

Trying to use the Worksheet.TableUpdate event in VBA with the following syntax.

«Private Sub Worksheet_TableUpdate(ByVal Target As TableObject)»

but the sub is not triggered when I refresh the only PowerQuery query in the document. The code is on the Sheet1 module as there’s only 1 sheet in the workbook.

What’s the correct syntax for this event? And could you provide a working example (i.e. one that you’ve tested)?

  • Moved by Emi Zhang Microsoft contingent staff Wednesday, September 21, 2016 6:35 AM Move Case

Answers

The event occurs after a Query table connected to the Data Model is updated on a worksheet.

Following Create a Data Model in Excel , I am adding data from Access and importing a Table.

Make sure «Add this data to the Data Model» checked.

The event fires after Importing and Refreshing.

All replies

This is the forum to discuss questions and feedback for Microsoft Excel, I’ll move your question to the MSDN forum for Excel

The reason why we recommend posting appropriately is you will get the most qualified pool of respondents, and other partners who read the forums regularly can either share their knowledge or learn from your interaction with us. Thank you for your understanding.

Regards,
Emi Zhang
TechNet Community Support

Источник

Vba excel событие tableupdate

Question

Trying to use the Worksheet.TableUpdate event in VBA with the following syntax.

«Private Sub Worksheet_TableUpdate(ByVal Target As TableObject)»

but the sub is not triggered when I refresh the only PowerQuery query in the document. The code is on the Sheet1 module as there’s only 1 sheet in the workbook.

What’s the correct syntax for this event? And could you provide a working example (i.e. one that you’ve tested)?

  • Moved by Emi Zhang Microsoft contingent staff Wednesday, September 21, 2016 6:35 AM Move Case

Answers

The event occurs after a Query table connected to the Data Model is updated on a worksheet.

Following Create a Data Model in Excel , I am adding data from Access and importing a Table.

Make sure «Add this data to the Data Model» checked.

The event fires after Importing and Refreshing.

All replies

This is the forum to discuss questions and feedback for Microsoft Excel, I’ll move your question to the MSDN forum for Excel

The reason why we recommend posting appropriately is you will get the most qualified pool of respondents, and other partners who read the forums regularly can either share their knowledge or learn from your interaction with us. Thank you for your understanding.

Regards,
Emi Zhang
TechNet Community Support

Источник

Adblock
detector

Как обработать событие Worksheet_TableUpdate

Stormy

Дата: Среда, 25.08.2021, 10:34 |
Сообщение № 1

Группа: Проверенные

Ранг: Обитатель

Сообщений: 357


Репутация:

12

±

Замечаний:
0% ±


Excel 2010

Добрый день, уважаемые.
Помогите с примером как обработать событие
[vba]

Код

Private Sub Worksheet_TableUpdate(ByVal Target As TableObject)
‘Что и как тут нужно указать, чтобы дальше сработали макросы ниже?
        Call UserAd
        Call Emsal
    End If
End Sub

[/vba]


Место для рекламы.

 

Ответить

bmv98rus

Дата: Среда, 25.08.2021, 11:20 |
Сообщение № 2

Группа: Друзья

Ранг: Участник клуба

Сообщений: 4009


Репутация:

760

±

Замечаний:
0% ±


Excel 2013/2016


Замечательный Временно просто медведь , процентов на 20.

 

Ответить

Stormy

Дата: Среда, 25.08.2021, 11:26 |
Сообщение № 3

Группа: Проверенные

Ранг: Обитатель

Сообщений: 357


Репутация:

12

±

Замечаний:
0% ±


Excel 2010

Видел эту статью, но все равно ничего не понял.
Событие нужно вызывать с листа на котором размещена обновляемая таблица, разместил, но эффекта 0.
Обошел этот момент открытием Активацией книги, пока вроде все работает и устраивает.
Но хотелось бы еще понимать как работает именно описываемое выше событие так как его могу использовать в разных случаях


Место для рекламы.

 

Ответить

bmv98rus

Дата: Среда, 25.08.2021, 11:38 |
Сообщение № 4

Группа: Друзья

Ранг: Участник клуба

Сообщений: 4009


Репутация:

760

±

Замечаний:
0% ±


Excel 2013/2016

обновляется то у Вас что?


Замечательный Временно просто медведь , процентов на 20.

 

Ответить

Stormy

Дата: Среда, 25.08.2021, 12:37 |
Сообщение № 5

Группа: Проверенные

Ранг: Обитатель

Сообщений: 357


Репутация:

12

±

Замечаний:
0% ±


Excel 2010

обновляется то у Вас что?

Таблица на листе, которая через Query берет данные с другого файла Excel


Место для рекламы.

Сообщение отредактировал StormyСреда, 25.08.2021, 12:38

 

Ответить

bmv98rus

Дата: Среда, 25.08.2021, 14:29 |
Сообщение № 6

Группа: Друзья

Ранг: Участник клуба

Сообщений: 4009


Репутация:

760

±

Замечаний:
0% ±


Excel 2013/2016

Это не то событие
Примерно так

[vba]

Код

‘ by ZVI  https://www.planetaexcel.ru/forum/index.php?PAGE_NAME=profile_view&UID=127
Dim WithEvents q As QueryTable

Private Sub q_AfterRefresh(ByVal Success As Boolean)
Debug.Print «AfterRefresh», Now
End Sub

Private Sub q_BeforeRefresh(Cancel As Boolean)
Debug.Print «BeforeRefresh», Now
End Sub

Private Sub Workbook_Open()
Application.OnTime Now, Me.Name & «.Start»
End Sub

Sub Start()
Set q = Sheet2.QueryTables(1)
End Sub

[/vba]


Замечательный Временно просто медведь , процентов на 20.

Сообщение отредактировал bmv98rusСреда, 25.08.2021, 14:30

 

Ответить

boa

Дата: Среда, 25.08.2021, 15:16 |
Сообщение № 7

Группа: Друзья

Ранг: Ветеран

Сообщений: 543


Репутация:

166

±

Замечаний:
0% ±


2013, 365

Здравствуйте,
Когда создаете таблицу на основе подключения, поставьте галочку добавить данные в модель данных

К сообщению приложен файл:

5077891.xlsb
(147.4 Kb)


 

Ответить

Stormy

Дата: Четверг, 26.08.2021, 12:33 |
Сообщение № 8

Группа: Проверенные

Ранг: Обитатель

Сообщений: 357


Репутация:

12

±

Замечаний:
0% ±


Excel 2010

boa,
Буду пробовать таким образом в след. редакциях


Место для рекламы.

 

Ответить

Stormy

Дата: Четверг, 26.08.2021, 12:35 |
Сообщение № 9

Группа: Проверенные

Ранг: Обитатель

Сообщений: 357


Репутация:

12

±

Замечаний:
0% ±


Excel 2010


Мне нужно было повесить выполнение макроса на какое-то событие.
Первое, что пришло на ум это использовать обновление таблицы, она обновляется при открытии файла.
После того как столкнулся с проблемой решил использовать событие книги Activation
Вроде все работает как хотелось бы.
Спасибо за потраченное время ))


Место для рекламы.

 

Ответить

Понравилась статья? Поделить с друзьями:
  • Vba excel событие exit
  • Vba excel смещение диапазона
  • Vba excel случайное число в диапазоне от
  • Vba excel событие enter
  • Vba excel сложить ячейки в excel