Hi, I am trying to import (applying some transformations) several tabs from a file. First I want the user to pick the file to be used for the import and then i have some filters applied. When i run the Macro, it gets loaded the original file that i loaded when run the macro. Even chosing a different file during the file picker, macro continues and loads data from a different file.
Sub Import_Report()
Dim FilePicker As FileDialog
Dim mypath10 As String
Set FilePicker = Application.FileDialog(msoFileDialogFilePicker)
With FilePicker
.Title = "Please Select Your File"
.AllowMultiSelect = False
.ButtonName = "Open"
If .Show = -1 Then
mypath = .SelectedItems(1)
Else
End
End If
End With
On Error Resume Next
ActiveWorkbook.Queries("Customer_Account").Delete
On Error GoTo 0
'
ActiveWorkbook.Queries.Add Name:="Customer_Account", Formula _
:= _
"let" & Chr(13) & "" & Chr(10) & " Source = mypath10, null, true)," & Chr(13) & "" & Chr(10) & " #""Customer Account Information_Sheet"" = Source{[Item=""Customer Account Information"",Kind=""Sheet""]}[Data]," &
{fields and filters}
ActiveWorkbook.Worksheets.Add
With ActiveSheet.ListObjects.Add(SourceType:=0, Source:= _
"OLEDB;Provider=Microsoft.Mashup.OleDb.1;Data Source=$Workbook$;Location=""Customer Account Information (3)"";Extended Properties=""""" _
, Destination:=Range("$A$1")).QueryTable
.CommandType = xlCmdSql
.CommandText = Array("SELECT * FROM [Customer Account Information (3)]")
.RowNumbers = False
.FillAdjacentFormulas = False
.PreserveFormatting = True
.RefreshOnFileOpen = False
.BackgroundQuery = True
.RefreshStyle = xlInsertDeleteCells
.SavePassword = False
.SaveData = True
.AdjustColumnWidth = True
.RefreshPeriod = 0
.PreserveColumnInfo = True
.Refresh BackgroundQuery:=False
Range("I2").Select
End With
Columns("A:A").Select
ActiveSheet.Name = "Customer_Summary"
Sub Import_Report()
Dim FilePicker As FileDialog
Dim mypath10 As String
Set FilePicker = Application.FileDialog(msoFileDialogFilePicker)
With FilePicker
.Title = "Please Select Your File"
.AllowMultiSelect = False
.ButtonName = "Open"
If .Show = -1 Then
mypath = .SelectedItems(1)
Else
End
End If
End With
On Error Resume Next
ActiveWorkbook.Queries("Customer_Account").Delete
On Error GoTo 0
'
ActiveWorkbook.Queries.Add Name:="Customer_Account", Formula _
:= _
"let" & Chr(13) & "" & Chr(10) & " Source = mypath10, null, true)," & Chr(13) & "" & Chr(10) & " #""Customer Account Information_Sheet"" = Source{[Item=""Customer Account Information"",Kind=""Sheet""]}[Data]," &
{fields and filters}
ActiveWorkbook.Worksheets.Add
With ActiveSheet.ListObjects.Add(SourceType:=0, Source:= _
"OLEDB;Provider=Microsoft.Mashup.OleDb.1;Data Source=$Workbook$;Location=""Customer Account Information (3)"";Extended Properties=""""" _
, Destination:=Range("$A$1")).QueryTable
.CommandType = xlCmdSql
.CommandText = Array("SELECT * FROM [Customer Account Information (3)]")
.RowNumbers = False
.FillAdjacentFormulas = False
.PreserveFormatting = True
.RefreshOnFileOpen = False
.BackgroundQuery = True
.RefreshStyle = xlInsertDeleteCells
.SavePassword = False
.SaveData = True
.AdjustColumnWidth = True
.RefreshPeriod = 0
.PreserveColumnInfo = True
.Refresh BackgroundQuery:=False
Range("I2").Select
End With
Columns("A:A").Select
ActiveSheet.Name = "Customer_Summary"