Macro

Annie313

New Member
Joined
Jun 29, 2015
Messages
1
Hi,

I'm trying to figure out what is wrong with this recorded macro.
Why is ListObject.DisplayName = "Table_Query_from_Excel_Files" showing up as an error?


' Macro9 Macro
'

'
With ActiveSheet.ListObjects.Add(SourceType:=0, Source:=Array(Array( _
"ODBC;DSN=Excel Files;DBQ=P:\00 Sales Administration\GPR Check\15-04 April GPR data v2.xls;DefaultDir=P:\00 Sales Administration\GPR " _
), Array("Check;DriverId=1046;MaxBufferSize=2048;PageTimeout=5;")), Destination _
:=Range("$A$2")).QueryTable
.CommandText = Array( _
"SELECT `data$`.`Responsible person`, `data$`.Category, `data$`.SALES_TYPE, `data$`.CUST_CODE, `data$`.CUST_PN, `data$`.DENSO_PN, `data$`.PROD_CODE, `data$`.FIS, `data$`.FIS_CURR, `data$`.VENDOR, `data" _
, _
"$`.FOB, `data$`.`FOB currency`, `data$`.`Actual GPR`, `data$`.`Exp# FOB`, `data$`.`Exp# GPR`, `data$`.QTY, `data$`.`Value of error`" & Chr(13) & "" & Chr(10) & "FROM `P:\00 Sales Administration\GPR Check\15-04 April GPR data v2." _
, _
"xls`.`data$` `data$`" & Chr(13) & "" & Chr(10) & "WHERE (`data$`.`Responsible person`='Daniel Robinson') AND (`data$`.Category='Loss') OR (`data$`.`Responsible person`='Fawwaz Siddiqi') AND (`data$`.Category='Loss') OR (`data$`." _
, _
"`Responsible person`='Serkan Kucuk') AND (`data$`.Category='Loss') OR (`data$`.`Responsible person`='Daniel Robinson') AND (`data$`.Category='Low Profit') OR (`data$`.`Responsible person`='Fawwaz Sidd" _
, _
"iqi') AND (`data$`.Category='Low Profit') OR (`data$`.`Responsible person`='Serkan Kucuk') AND (`data$`.Category='Low Profit') OR (`data$`.`Responsible person`='Colin Norton') AND (`data$`.Category='L" _
, _
"oss') OR (`data$`.`Responsible person`='Colin Norton') AND (`data$`.Category='Low Profit') OR (`data$`.`Responsible person`='Daniel Robinson') AND (`data$`.Category='High Profit') OR (`data$`.`Respons" _
, _
"ible person`='Fawwaz Siddiqi') AND (`data$`.Category='High Profit') OR (`data$`.`Responsible person`='Serkan Kucuk') AND (`data$`.Category='High Profit') OR (`data$`.`Responsible person`='Colin Norton" _
, "') AND (`data$`.Category='High Profit')")
.RowNumbers = False
.FillAdjacentFormulas = False
.PreserveFormatting = True
.RefreshOnFileOpen = False
.BackgroundQuery = True
.RefreshStyle = xlInsertDeleteCells
.SavePassword = False
.SaveData = True
.AdjustColumnWidth = True
.RefreshPeriod = 0
.PreserveColumnInfo = True
.ListObject.DisplayName = "Table_Query_from_Excel_Files" .Refresh BackgroundQuery:=False
End With
Range("D5").Select
ActiveWindow.SmallScroll Down:=138
Application.WindowState = xlMinimized
Application.WindowState = xlNormal
ActiveWindow.SmallScroll Down:=-180
End Sub


Hope you can help
 

Excel Facts

Remove leading & trailing spaces
Save as CSV to remove all leading and trailing spaces. It is faster than using TRIM().
being pedantic

.ListObject.DisplayName = "Table_Query_from_Excel_Files"
.Refresh BackgroundQuery:=False

does the name "Table_Query_from_Excel_Files" already exist?? in the workbook
 
Upvote 0

Forum statistics

Threads
1,223,237
Messages
6,170,928
Members
452,366
Latest member
TePunaBloke

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top