Sub Load_PBoM1()
'
' Load PBoM1
'
'***************************
'Check to see if the table already exists on any of the existing tabs.
Dim ws As Worksheet
Dim PBoM1 As String
Dim tbl As ListObject
For Each ws In ActiveWorkbook.Worksheets
If ws.ListObjects("PBoM1").Name = "PBoM1" Then
ws.ListObjects("PBoM1").QueryTable.Refresh BackgroundQuery:=False
Sheets("Task List").Range("H1").Value = 1
Exit For
End If
Next ws
'
'*******************************
'If the table does not currently exist on any of the tabs, then create a tab and load the table.
If Sheets("Task List").Range("H1").Value <> 1 Then
'On Error GoTo Skip
Application.CutCopyMode = False
ActiveWorkbook.Worksheets.Add
With ActiveSheet.ListObjects.Add(SourceType:=0, Source:= _
"OLEDB;Provider=Microsoft.Mashup.OleDb.1;Data Source=$Workbook$;Location=PBoM1;Extended Properties=""""" _
, Destination:=Range("$B$15")).QueryTable
.CommandType = xlCmdSql
.CommandText = Array("SELECT * FROM [PBoM1]")
.RowNumbers = False
.FillAdjacentFormulas = False
.PreserveFormatting = True
.RefreshOnFileOpen = False
.BackgroundQuery = True
.RefreshStyle = xlInsertDeleteCells
.SavePassword = False
.SaveData = True
.AdjustColumnWidth = True
.RefreshPeriod = 0
.PreserveColumnInfo = True
.ListObject.DisplayName = "PBoM1"
.Refresh BackgroundQuery:=False
End With
'Skip:
' On Error GoTo 0
Else
End If
End Sub