I'm trying this simple Sub (in Excel 2019) to import tables from a specific Yahoo Finance page.
It works with other websites, but with Yahoo Finance, I keep getting the same message "This Web query returned no data. To change..........." and no data is extracted.
I couldn't figure out the reason.
Sub ImportTable()
Dim ws As Worksheet
Dim qt As QueryTable
Dim qurl As String
qurl = "https://finance.yahoo.com/quote/MSFT/key-statistics?p=MSFT"
Set ws = worksheets.Add
Set qt = ws.QueryTables.Add( _
Connection:="URL;" & qurl, _
Destination:=Range("A1"))
With qt
.RefreshOnFileOpen = False
.Name = "test"
.WebFormatting = xlWebFormattingNone
.WebSelectionType = xlAllTables
.Refresh
End With
End Sub
You can instead set-up connections to the various tables which will add them to the data model (Alt + B + M). In the queries pane of data you can then chose where to load them to your workbook if you wish to see them. You can also just work with them in the data model and generate your final desired output.
Note:
The quicker way is, from ribbon, to do, data > from web > enter url > select tables of interest. This will set-up table connections without vba.
VBA:
Option Explicit
Public Sub AddYahooFinanceTableConnections()
Dim wb As ThisWorkbook
Set wb = ThisWorkbook
wb.Queries.Add Name:="Balance Sheet", Formula:= _
"let" & Chr(13) & "" & Chr(10) & " Source = Web.Page(Web.Contents(""https://finance.yahoo.com/quote/MSFT/key-statistics?p=MSFT""))," & Chr(13) & "" & Chr(10) & " Data10 = Source{10}[Data]," & Chr(13) & "" & Chr(10) & " #""Changed Type"" = Table.TransformColumnTypes(Data10,{{""Total Cash (mrq)"", type text}, {""131.99B"", type text}})" & Chr(13) & "" & Chr(10) & "in" & Chr(13) & "" & Chr(10) & " #""Changed Type"""
wb.Queries.Add Name:="Cash Flow Statement", Formula:= _
"let" & Chr(13) & "" & Chr(10) & " Source = Web.Page(Web.Contents(""https://finance.yahoo.com/quote/MSFT/key-statistics?p=MSFT""))," & Chr(13) & "" & Chr(10) & " Data11 = Source{11}[Data]," & Chr(13) & "" & Chr(10) & " #""Changed Type"" = Table.TransformColumnTypes(Data11,{{""Column1"", type text}, {""Column2"", type text}})" & Chr(13) & "" & Chr(10) & "in" & Chr(13) & "" & Chr(10) & " #""Changed Type"""
wb.Queries.Add Name:="Dividends & Splits", Formula:= _
"let" & Chr(13) & "" & Chr(10) & " Source = Web.Page(Web.Contents(""https://finance.yahoo.com/quote/MSFT/key-statistics?p=MSFT""))," & Chr(13) & "" & Chr(10) & " Data5 = Source{5}[Data]," & Chr(13) & "" & Chr(10) & " #""Changed Type"" = Table.TransformColumnTypes(Data5,{{""Forward Annual Dividend Rate"", type text}, {""2.24"", type text}})" & Chr(13) & "" & Chr(10) & "in" & Chr(13) & "" & Chr(10) & " #""Changed Type"""
wb.Queries.Add Name:="Fiscal Year", Formula:= _
"let" & Chr(13) & "" & Chr(10) & " Source = Web.Page(Web.Contents(""https://finance.yahoo.com/quote/MSFT/key-statistics?p=MSFT""))," & Chr(13) & "" & Chr(10) & " Data6 = Source{6}[Data]," & Chr(13) & "" & Chr(10) & " #""Changed Type"" = Table.TransformColumnTypes(Data6,{{""Column1"", type text}, {""Column2"", type date}})" & Chr(13) & "" & Chr(10) & "in" & Chr(13) & "" & Chr(10) & " #""Changed Type"""
wb.Queries.Add Name:="Income Statement", Formula:= _
"let" & Chr(13) & "" & Chr(10) & " Source = Web.Page(Web.Contents(""https://finance.yahoo.com/quote/MSFT/key-statistics?p=MSFT""))," & Chr(13) & "" & Chr(10) & " Data9 = Source{9}[Data]," & Chr(13) & "" & Chr(10) & " #""Changed Type"" = Table.TransformColumnTypes(Data9,{{""Revenue (ttm)"", type text}, {""153.28B"", type text}})" & Chr(13) & "" & Chr(10) & "in" & Chr(13) & "" & Chr(10) & " #""Changed Type"""
wb.Queries.Add Name:="People Also Watch", Formula:= _
"let" & Chr(13) & "" & Chr(10) & " Source = Web.Page(Web.Contents(""https://finance.yahoo.com/quote/MSFT/key-statistics?p=MSFT""))," & Chr(13) & "" & Chr(10) & " Data12 = Source{12}[Data]," & Chr(13) & "" & Chr(10) & " #""Changed Type"" = Table.TransformColumnTypes(Data12,{{""Symbol"", type text}, {""Last Price"", type number}, {""Change"", type number}, {""% Change"", Percentage.Type}})" & Chr(13) & "" & Chr(10) & "in" & Chr(13) & "" & Chr(10) & " #""Changed Type"""
wb.Queries.Add Name:="Profitability", Formula:= _
"let" & Chr(13) & "" & Chr(10) & " Source = Web.Page(Web.Contents(""https://finance.yahoo.com/quote/MSFT/key-statistics?p=MSFT""))," & Chr(13) & "" & Chr(10) & " Data7 = Source{7}[Data]," & Chr(13) & "" & Chr(10) & " #""Changed Type"" = Table.TransformColumnTypes(Data7,{{""Column1"", type text}, {""Column2"", Percentage.Type}})" & Chr(13) & "" & Chr(10) & "in" & Chr(13) & "" & Chr(10) & " #""Changed Type"""
wb.Queries.Add Name:="Share Statistics", Formula:= _
"let" & Chr(13) & "" & Chr(10) & " Source = Web.Page(Web.Contents(""https://finance.yahoo.com/quote/MSFT/key-statistics?p=MSFT""))," & Chr(13) & "" & Chr(10) & " Data4 = Source{4}[Data]," & Chr(13) & "" & Chr(10) & " #""Changed Type"" = Table.TransformColumnTypes(Data4,{{""Avg Vol (3 month)"", type text}, {""30.36M"", type text}})" & Chr(13) & "" & Chr(10) & "in" & Chr(13) & "" & Chr(10) & " #""Changed Type"""
wb.Queries.Add Name:="Stock Price History", Formula:= _
"let" & Chr(13) & "" & Chr(10) & " Source = Web.Page(Web.Contents(""https://finance.yahoo.com/quote/MSFT/key-statistics?p=MSFT""))," & Chr(13) & "" & Chr(10) & " Data3 = Source{3}[Data]," & Chr(13) & "" & Chr(10) & " #""Changed Type"" = Table.TransformColumnTypes(Data3,{{""Beta (5Y Monthly)"", type text}, {""0.79"", type number}})" & Chr(13) & "" & Chr(10) & "in" & Chr(13) & "" & Chr(10) & " #""Changed Type"""
wb.Queries.Add Name:="Table 0", Formula:= _
"let" & Chr(13) & "" & Chr(10) & " Source = Web.Page(Web.Contents(""https://finance.yahoo.com/quote/MSFT/key-statistics?p=MSFT""))," & Chr(13) & "" & Chr(10) & " Data0 = Source{0}[Data]," & Chr(13) & "" & Chr(10) & " #""Changed Type"" = Table.TransformColumnTypes(Data0,{{""Column1"", type text}, {""Column2"", type text}})" & Chr(13) & "" & Chr(10) & "in" & Chr(13) & "" & Chr(10) & " #""Changed Type"""
wb.Queries.Add Name:="Table 1", Formula:= _
"let" & Chr(13) & "" & Chr(10) & " Source = Web.Page(Web.Contents(""https://finance.yahoo.com/quote/MSFT/key-statistics?p=MSFT""))," & Chr(13) & "" & Chr(10) & " Data1 = Source{1}[Data]," & Chr(13) & "" & Chr(10) & " #""Changed Type"" = Table.TransformColumnTypes(Data1,{{""Column1"", type text}, {""Column2"", type text}})" & Chr(13) & "" & Chr(10) & "in" & Chr(13) & "" & Chr(10) & " #""Changed Type"""
wb.Connections.Add2 "Query - Balance Sheet", _
"Connection to the 'Balance Sheet' query in the workbook.", _
"OLEDB;Provider=Microsoft.Mashup.OleDb.1;Data Source=$Workbook$;Location=Balance Sheet;Extended Properties=" _
, """Balance Sheet""", 6, True, False
wb.Connections.Add2 "Query - Cash Flow Statement", _
"Connection to the 'Cash Flow Statement' query in the workbook.", _
"OLEDB;Provider=Microsoft.Mashup.OleDb.1;Data Source=$Workbook$;Location=Cash Flow Statement;Extended Properties=" _
, """Cash Flow Statement""", 6, True, False
wb.Connections.Add2 "Query - Dividends & Splits", _
"Connection to the 'Dividends & Splits' query in the workbook.", _
"OLEDB;Provider=Microsoft.Mashup.OleDb.1;Data Source=$Workbook$;Location=Dividends & Splits;Extended Properties=" _
, """Dividends & Splits""", 6, True, False
wb.Connections.Add2 "Query - Fiscal Year", _
"Connection to the 'Fiscal Year' query in the workbook.", _
"OLEDB;Provider=Microsoft.Mashup.OleDb.1;Data Source=$Workbook$;Location=Fiscal Year;Extended Properties=" _
, """Fiscal Year""", 6, True, False
wb.Connections.Add2 "Query - Income Statement", _
"Connection to the 'Income Statement' query in the workbook.", _
"OLEDB;Provider=Microsoft.Mashup.OleDb.1;Data Source=$Workbook$;Location=Income Statement;Extended Properties=" _
, """Income Statement""", 6, True, False
wb.Connections.Add2 "Query - People Also Watch", _
"Connection to the 'People Also Watch' query in the workbook.", _
"OLEDB;Provider=Microsoft.Mashup.OleDb.1;Data Source=$Workbook$;Location=People Also Watch;Extended Properties=" _
, """People Also Watch""", 6, True, False
wb.Connections.Add2 "Query - Profitability", _
"Connection to the 'Profitability' query in the workbook.", _
"OLEDB;Provider=Microsoft.Mashup.OleDb.1;Data Source=$Workbook$;Location=Profitability;Extended Properties=" _
, """Profitability""", 6, True, False
wb.Connections.Add2 "Query - Share Statistics", _
"Connection to the 'Share Statistics' query in the workbook.", _
"OLEDB;Provider=Microsoft.Mashup.OleDb.1;Data Source=$Workbook$;Location=Share Statistics;Extended Properties=" _
, """Share Statistics""", 6, True, False
wb.Connections.Add2 "Query - Stock Price History", _
"Connection to the 'Stock Price History' query in the workbook.", _
"OLEDB;Provider=Microsoft.Mashup.OleDb.1;Data Source=$Workbook$;Location=Stock Price History;Extended Properties=" _
, """Stock Price History""", 6, True, False
wb.Connections.Add2 "Query - Table 0", _
"Connection to the 'Table 0' query in the workbook.", _
"OLEDB;Provider=Microsoft.Mashup.OleDb.1;Data Source=$Workbook$;Location=Table 0;Extended Properties=" _
, """Table 0""", 6, True, False
wb.Connections.Add2 "Query - Table 1", _
"Connection to the 'Table 1' query in the workbook.", _
"OLEDB;Provider=Microsoft.Mashup.OleDb.1;Data Source=$Workbook$;Location=Table 1;Extended Properties=" _
, """Table 1""", 6, True, False
End Sub
So I have a bit of a problem with some query connections that I want to deal with inside an array because they can hold more rows than Excel can handle.
Option Explicit
Sub RefrescaConsultas()
EliminaConsultas
CreaConsultas
End Sub
Private Sub EliminaConsultas()
Dim Consulta As Object
For Each Consulta In ThisWorkbook.Queries
Consulta.Delete
Next Consulta
End Sub
Private Sub CreaConsultas()
Dim Mes As String: Mes = HMacro.Range("B2")
Dim Año As Long: Año = HMacro.Range("B1")
Dim MesNum As Byte: MesNum = Month(DateValue("01/" & Mes & "/2020"))
Dim RutaAccess As String: RutaAccess = Chr(34) & "\\ate2899cor01\reporting_administrativos\TELEFONICA\GP\Informe Evolucion Territorios\2020\Modelo Marzo´20\Inforrme Evolucion Ventas\Nuevo informe\BBDD\Actualiza Conversores.accdb" & Chr(34)
'Brutas
ThisWorkbook.Queries.Add "Brutas", "let" & Chr(13) & "" & Chr(10) & " Origen = Access.Database(File.Contents(" & RutaAccess & "), [CreateNavigationProperties=true])," & Chr(13) & "" & Chr(10) & " _Brutas = Origen{[Schema="""",Item=""Brutas""]}[Data]," & Chr(13) & "" & Chr(10) & " #""Columnas quitadas"" = Table.Rem" & _
"oveColumns(_Brutas,{""fx_proceso"", ""fx_estado_fin"", ""fx_devengo"", ""estado"", ""cod_indicador_negocio_alta_comercial"", ""producto_alta_comercial"", ""subproducto_origen_alta_comercial"", ""soporte"", ""faro"", ""codigo_pedido"", ""tipo_doc"", ""id_fiscal"", ""CUC"", " & _
"""telefono"", ""segmento"", ""provincia_cliente"", ""ccaa_cliente"", ""territorio_cliente"", ""vendedor"", ""canal_venta"", ""co_proveedor"", ""no_empresa"", ""co_centro_venta"", ""provincia_venta"", ""ccaa_venta"", ""territorio_venta"", ""FechaGrab"", ""unidades"", ""producto_comision_alta_comercial"", ""producto_comision_actualizad" & _
"o"", ""importe_comision"", ""COD_T9"", ""rf_tq"", ""operacion"", ""sub_producto_destino_alta_comercial"", ""num_lineas_movil_tipo_fusion"", ""num_lineas_movil_planta"", ""in_fusion"", ""anul_15"", ""anul_30"", ""anul_60"", ""co_resolucion_sia"", ""resolucion_sia"", ""causa_anulacion"", ""fuente_origen"", ""cliente_nuevo"", ""in_servicio_tv""})," & Chr(13) & "" & Chr(10) & " #""Filas filtradas"" = Table.SelectRows(#""Columnas quitadas"", each Dat" & _
"e.Month([fx_solicitud]) = " & MesNum & ")" & Chr(13) & "" & Chr(10) & "in" & Chr(13) & "" & Chr(10) & " #""Filas filtradas"""
'TV
ThisWorkbook.Queries.Add "TV", "let" & Chr(13) & "" & Chr(10) & " Origen = Access.Database(File.Contents(" & RutaAccess & "), [CreateNavigationProperties=true])," & Chr(13) & "" & Chr(10) & " _TV = Origen{[Schema="""",Item=""TV""]}[Data]," & Chr(13) & "" & Chr(10) & " #""Columnas quitadas"" = Table.RemoveColum" & _
"ns(_TV,{""fx_proceso"", ""fx_estado_fin"", ""fx_devengo"", ""estado"", ""operacion"", ""cod_indicador_negocio_alta_comercial"", ""producto_alta_comercial"", ""sub_producto_destino_alta_comercial"", ""subproducto_origen_alta_comercial"", ""soporte"", ""codigo_pedido"", ""tipo_doc"", ""id_fiscal"", ""CUC"", ""telefono"", ""segmento"", ""provincia_cliente"", ""ccaa_cli" & _
"ente"", ""territorio_cliente"", ""vendedor"", ""canal_venta"", ""co_proveedor"", ""no_empresa"", ""co_centro_venta"", ""no_sucursal"", ""provincia_venta"", ""ccaa_venta"", ""territorio_venta"", ""FechaGrab"", ""unidades"", ""baja_prematura"", ""dias_baja"", ""producto_comision_alta_comercial"", ""importe_comision"", ""COD_T9"", ""rf_tq"", ""nu_administra"", ""fuente" & _
"_origen"", ""ds_fusion_origen"", ""ds_fusion_destino"", ""baja_prematura_8_mes_sig"", ""IN_PLANTA_8_MES_SIG"", ""CLIENTE_NUEVO""})," & Chr(13) & "" & Chr(10) & " #""Filas filtradas"" = Table.SelectRows(#""Columnas quitadas"", each Date.Month([fx_solicitud]) = " & MesNum & ")" & Chr(13) & "" & Chr(10) & "in" & Chr(13) & "" & Chr(10) & " #""Filas filtradas"""
'Fusion
ThisWorkbook.Queries.Add "Fusion", "let" & Chr(13) & "" & Chr(10) & " Origen = Access.Database(File.Contents(" & RutaAccess & "), [CreateNavigationProperties=true])," & Chr(13) & "" & Chr(10) & " _Fusion = Origen{[Schema="""",Item=""Fusion""]}[Data]," & Chr(13) & "" & Chr(10) & " #""Columnas quitadas"" = Table.Rem" & _
"oveColumns(_Fusion,{""fx_proceso"", ""fx_solicitud"", ""fx_devengo"", ""fx_instalacion"", ""estado"", ""operacion"", ""cod_indicador_negocio_alta_comercial"", ""producto_alta_comercial"", ""sub_producto_destino_alta_comercial"", ""subproducto_origen_alta_comercial"", ""soporte"", ""codigo_pedido"", ""tipo_doc"", ""id_fiscal"", ""telefono"", ""segmento"", ""provincia" & _
"_cliente"", ""ccaa_cliente"", ""territorio_cliente"", ""vendedor"", ""matricula_origen"", ""canal_venta"", ""co_proveedor"", ""no_empresa"", ""co_centro_venta"", ""provincia_venta"", ""ccaa_venta"", ""territorio_venta"", ""FechaGrab"", ""unidades"", ""baja_prematura"", ""producto_comision_alta_comercial"", ""COD_T9"", ""valor_origen"", ""valor_destino"", ""rf_tq"", " & _
"""dif_dias_baja"", ""in_servicio_tv_origen"", ""in_servicio_tv_destino"", ""num_lineas_movil_tipo_fusion"", ""num_lineas_movil_planta"", ""CUC"", ""fuente_origen"", ""fx_alta_desco""})," & Chr(13) & "" & Chr(10) & " #""Filas filtradas"" = Table.SelectRows(#""Columnas quitadas"", each Date.Month([fx_estado_fin]) = " & MesNum & ")" & Chr(13) & "" & Chr(10) & "in" & Chr(13) & "" & Chr(10) & " #""Filas filtradas"""
'Inserciones
ThisWorkbook.Queries.Add "Inserciones", "let" & Chr(13) & "" & Chr(10) & " Origen = Access.Database(File.Contents(" & RutaAccess & "), [CreateNavigationProperties=true])," & Chr(13) & "" & Chr(10) & " _Inserciones = Origen{[Schema="""",Item=""Inserciones""]}[Data]," & Chr(13) & "" & Chr(10) & " #""Columnas quitadas"" =" & _
" Table.RemoveColumns(_Inserciones,{""fx_proceso"", ""fx_estado_fin"", ""estado"", ""causa_estado"", ""operacion"", ""cod_indicador_negocio_alta_comercial"", ""indicador_negocio_alta_comercial"", ""subproducto_origen_alta_comercial"", ""soporte"", ""codigo_pedido"", ""tipo_doc"", ""id_fiscal"", ""CUC"", ""telefono"", ""segmento"", ""provi" & _
"ncia_cliente"", ""ccaa_cliente"", ""territorio_cliente"", ""vendedor"", ""canal_venta"", ""co_proveedor"", ""no_empresa"", ""co_centro_venta"", ""provincia_venta"", ""ccaa_venta"", ""territorio_venta"", ""FechaGrab"", ""unidades"", ""cod_comision_alta_comercial"", ""producto_comision_alta_comercial"", ""importe_comision"", ""co_contrato"", ""co_plantari"", ""operado" & _
"r_origen"", ""operador_destino"", ""ICC"", ""LIQUIDABLE"", ""TARJETA_VIRTUAL"", ""NUMERO_REPETICIONES"", ""FUENTE_ORIGEN""})," & Chr(13) & "" & Chr(10) & " #""Filas filtradas"" = Table.SelectRows(#""Columnas quitadas"", each Date.Month([fx_solicitud]) = " & MesNum & ")" & Chr(13) & "" & Chr(10) & "in" & Chr(13) & "" & Chr(10) & " #""Filas filtradas"""
'Prosegur
ThisWorkbook.Queries.Add "Prosegur", "let" & Chr(13) & "" & Chr(10) & " Origen = Access.Database(File.Contents(" & RutaAccess & "), [CreateNavigationProperties=true])," & Chr(13) & "" & Chr(10) & " _Prosegur = Origen{[Schema="""",Item=""Prosegur""]}[Data]," & Chr(13) & "" & Chr(10) & " #""Columnas quitadas"" = Table" & _
".RemoveColumns(_Prosegur,{""fx_proceso"", ""fx_estado_fin"", ""fx_devengo"", ""estado"", ""operacion"", ""cod_indicador_negocio_solicitado"", ""indicador_negocio_solicitado"", ""producto_solicitado"", ""sub_producto_destino_solicitado"", ""subproducto_origen_solicitado"", ""cod_indicador_negocio_alta_comercial"", ""producto_alta_comercial"", ""sub_producto_destino_a" & _
"lta_comercial"", ""subproducto_origen_alta_comercial"", ""soporte"", ""codigo_pedido"", ""CUC"", ""tipo_doc"", ""id_fiscal"", ""telefono"", ""segmento"", ""localidad_cliente"", ""provincia_cliente"", ""ccaa_cliente"", ""territorio_cliente"", ""vendedor"", ""matricula_origen"", ""canal_venta"", ""co_proveedor"", ""no_empresa"", ""co_centro_venta"", ""provincia_venta" & _
""", ""ccaa_venta"", ""territorio_venta"", ""pais_vendedor"", ""FechaGrab"", ""FechaGrabInci"", ""in_fusion"", ""tipo"", ""nu_administra"", ""unidades"", ""id_senializacion"", ""cod_comision_solicitado"", ""producto_comision_solicitado"", ""producto_comision_alta_comercial"", ""id_lead"", ""COD_T9"", ""rf_tq"", ""producto_comision_actualizado"", ""fuente_origen"", """ & _
"co_unico"", ""fecha_compromiso_ini"", ""fecha_alta_sistema"", ""Campo61"", ""Campo62"", ""Campo63""})," & Chr(13) & "" & Chr(10) & " #""Filas filtradas"" = Table.SelectRows(#""Columnas quitadas"", each Date.Month([fx_solicitud]) = " & MesNum & ")" & Chr(13) & "" & Chr(10) & "in" & Chr(13) & "" & Chr(10) & " #""Filas filtradas"""
'Repos Móvil
ThisWorkbook.Queries.Add "Repos", "let" & Chr(13) & "" & Chr(10) & " Origen = Access.Database(File.Contents(" & RutaAccess & "), [CreateNavigationProperties=true])," & Chr(13) & "" & Chr(10) & " _Repos = Origen{[Schema="""",Item=""Repos""]}[Data]," & Chr(13) & "" & Chr(10) & " #""Columnas quitadas"" = Table.Remov" & _
"eColumns(_Repos,{""fx_proceso"", ""fx_solicitud"", ""fx_devengo"", ""estado"", ""operacion"", ""cod_indicador_negocio_solicitado"", ""indicador_negocio_solicitado"", ""sub_producto_origen_alta_comercial"", ""subproducto_origen_alta_comercial"", ""cod_indicador_negocio_alta_comercial"", ""sub_producto_destino_alta_comercial"", ""subproducto_destino_alta_comercial"", " & _
"""soporte"", ""codigo_pedido"", ""tipo_doc"", ""id_fiscal"", ""CUC"", ""telefono"", ""segmento"", ""localidad_cliente"", ""provincia_cliente"", ""ccaa_cliente"", ""territorio_cliente"", ""vendedor"", ""matricula_origen"", ""canal_venta"", ""co_proveedor"", ""no_empresa"", ""co_centro_venta"", ""provincia_venta"", ""ccaa_venta"", ""territorio_venta"", ""pais_vendedor" & _
""", ""in_fusion"", ""tipo"", ""operador_origen"", ""operador_destino"", ""in_terminal"", ""FechaGrab"", ""FechaGrabInci"", ""co_contrato_origen"", ""co_contrato_destino"", ""co_plantari_origen"", ""co_plantari_destino"", ""cod_comision_solicitado"", ""producto_comision_solicitado"", ""producto_comision_alta_comercial"", ""ICC"", ""FUENTE_ORIGEN"", ""Arpu_Origen"", " & _
"""Arpu_Destino"", ""unidades""})," & Chr(13) & "" & Chr(10) & " #""Filas filtradas"" = Table.SelectRows(#""Columnas quitadas"", each Date.Month([fx_estado_fin]) = " & MesNum & ")" & Chr(13) & "" & Chr(10) & "in" & Chr(13) & "" & Chr(10) & " #""Filas filtradas"""
'Terminales
ThisWorkbook.Queries.Add "Terminales", "let" & Chr(13) & "" & Chr(10) & " Origen = Access.Database(File.Contents(" & RutaAccess & "), [CreateNavigationProperties=true])," & Chr(13) & "" & Chr(10) & " _Terminales = Origen{[Schema="""",Item=""Terminales""]}[Data]," & Chr(13) & "" & Chr(10) & " #""Columnas quitadas"" = T" & _
"able.RemoveColumns(_Terminales,{""fx_proceso"", ""fx_solicitud"", ""fx_devengo"", ""estado"", ""operacion"", ""cod_indicador_negocio_alta_comercial"", ""producto_alta_comercial"", ""sub_producto_destino_alta_comercial"", ""subproducto_origen_alta_comercial"", ""soporte"", ""codigo_pedido"", ""tipo_doc"", ""id_fiscal"", ""CUC"", ""telefono"", ""segmento"", ""provinci" & _
"a_cliente"", ""ccaa_cliente"", ""territorio_cliente"", ""vendedor"", ""canal_venta"", ""co_proveedor"", ""no_empresa"", ""co_centro_venta"", ""provincia_venta"", ""ccaa_venta"", ""territorio_venta"", ""FechaGrab"", ""unidades"", ""producto_comision_alta_comercial"", ""importe_comision"", ""vendedor_entrega"", ""canal_venta_entrega"", ""agrupacion_canal_entrega"", """ & _
"canal_entrega"", ""detalle_canal_entrega"", ""co_proveedor_entrega"", ""no_empresa_entrega"", ""co_centro_venta_entrega"", ""no_sucursal_entrega"", ""provincia_venta_entrega"", ""territorio_venta_entrega"", ""tipo"", ""gama_terminal"", ""in_financiado"", ""nu_imei"", ""cod_campania"", ""FUENTE_ORIGEN"", ""Campo56"", ""Campo57"", ""Campo58"", ""Campo59"", ""Campo60""" & _
", ""Campo61""})," & Chr(13) & "" & Chr(10) & " #""Filas filtradas"" = Table.SelectRows(#""Columnas quitadas"", each Date.Month([fx_estado_fin]) = " & MesNum & ")" & Chr(13) & "" & Chr(10) & "in" & Chr(13) & "" & Chr(10) & " #""Filas filtradas"""
'Móvil
ThisWorkbook.Queries.Add "Movil", "let" & Chr(13) & "" & Chr(10) & " Origen = Access.Database(File.Contents(" & RutaAccess & "), [CreateNavigationProperties=true])," & Chr(13) & "" & Chr(10) & " _Movil = Origen{[Schema="""",Item=""Movil""]}[Data]," & Chr(13) & "" & Chr(10) & " #""Columnas quitadas"" = Table.Remov" & _
"eColumns(_Movil,{""fx_proceso"", ""fx_solicitud"", ""fx_devengo"", ""estado"", ""operacion"", ""cod_indicador_negocio_alta_comercial"", ""subproducto_origen_alta_comercial"", ""co_modven"", ""soporte"", ""codigo_pedido"", ""tipo_doc"", ""id_fiscal"", ""CUC"", ""telefono"", ""segmento"", ""provincia_cliente"", ""ccaa_cliente"", ""territorio_cliente"", ""vendedor"", " & _
"""canal_venta"", ""co_proveedor"", ""no_empresa"", ""co_centro_venta"", ""provincia_venta"", ""ccaa_venta"", ""territorio_venta"", ""FechaGrab"", ""unidades"", ""baja_prematura"", ""dif_dias_baja"", ""producto_comision_alta_comercial"", ""importe_comision"", ""in_terminal"", ""co_contrato"", ""co_plantari"", ""operador_origen"", ""operador_destino"", ""ICC"", ""fuen" & _
"te_origen""})," & Chr(13) & "" & Chr(10) & " #""Filas filtradas"" = Table.SelectRows(#""Columnas quitadas"", each Date.Month([fx_estado_fin]) = " & MesNum & ")" & Chr(13) & "" & Chr(10) & "in" & Chr(13) & "" & Chr(10) & " #""Filas filtradas"""
'TMO
ThisWorkbook.Queries.Add "TMO", "let" & Chr(13) & "" & Chr(10) & " Origen = Access.Database(File.Contents(" & RutaAccess & "), [CreateNavigationProperties=true])," & Chr(13) & "" & Chr(10) & " _TMO = Origen{[Schema="""",Item=""TMO""]}[Data]," & Chr(13) & "" & Chr(10) & " #""Columnas quitadas"" = Table.RemoveCol" & _
"umns(_TMO,{""semana"", ""New_Territorio"", ""PAIS_TABLA"", ""MODO TABLA"", ""MODO TABLA TMO"", ""FX_LLAMADA"", ""NO_SEGMENTO"", ""NO_TERRITORIO"", ""NO_SUBTERRITORIO"", ""NO_PROVEEDOR"", ""NO_ORIGEN"", ""Terri_cliente"", ""Subterri_cliente"", ""ORIGEN"", ""NO_SEGMENTO_SKILL"", ""CO_GRABACION"", ""CLIENTE_NUEVO"", ""DS_SEGMENTO_ORGANIZATIVO"", ""B2C"", ""Idioma"", """ & _
"CO_TIPO_EMISION"", ""IN_AGENDADA"", ""CA_RECIBIDAS"", ""CA_LLAMADAA_VALIDAA"", ""CA_Atendidas_Entrantes"", ""CA_Aten_20seg"", ""CA_Conv_M20Seg"", ""CA_TMO"", ""CA_TMO_S"", ""CA_TME"", ""CA_Tr_Imputables"", ""CA_Transferidas"", ""CA_Salientes"", ""CA_AGENDADAS"", ""CA_TMO_AGENDADAS""})," & Chr(13) & "" & Chr(10) & " #""Filas filtradas"" = Table.SelectRows(#""Columnas quitadas"", each [Mes] =" & _
MesNum & ")," & Chr(13) & "" & Chr(10) & " #""Filas filtradas1"" = Table.SelectRows(#""Filas filtradas"", each [Año] = " & Año & ")" & Chr(13) & "" & Chr(10) & "in" & Chr(13) & "" & Chr(10) & " #""Filas filtradas1"""
End Sub
The code is fairly simple, I've manually recorded Data->from data base->selected the data base->deleted some columns for each connection and filtered some data.
Now the workbook has all these connections that I need to work with, but pasting them into a sheet and then into an array might be a problem because some of them are more than 1M rows... Any Insight on how to achieve this?
Specifications and Limits for Excel Worksheets and Workbooks
Total number of rows and columns in a worksheet :
1,048,576 rows and 16,384 columns
so you may have to add a clause to limit the number of rows: select TOP 1000 in your SQL request
With ActiveSheet.ListObjects.Add(SourceType:=0, Source:= _
"OLEDB;Provider=Microsoft.Mashup.OleDb.1;Data Source=$Workbook$;Location=Customer;Extended Properties=""""" _
, Destination:=Range("$A$1")).QueryTable
.CommandType = xlCmdSql
.CommandText = Array("SELECT TOP 10OO fx_proceso FROM [Prosegur]")