I want to execute an existing macro in a workbook named A on an another workbook B. I tried to write a vba code in B to call the macro but it keeps execute in A.
Here is the macro:
Sub LoadQueries()
' TestQueries Macro
Sheets.Add After:=ActiveSheet
Sheets("Feuil1").Select
Sheets("Feuil1").Name = "questions"
Sheets.Add After:=ActiveSheet
Sheets("Feuil2").Select
Sheets("Feuil2").Name = "clean"
Sheets("questions").Select
Application.CutCopyMode = False
With ActiveSheet.ListObjects.Add(SourceType:=0, Source:= _
"OLEDB;Provider=Microsoft.Mashup.OleDb.1;Data Source=$Workbook$;Location=questions;Extended Properties=""""" _
, Destination:=Range("$A$1")).QueryTable
.CommandType = xlCmdSql
.CommandText = Array("SELECT * FROM [questions]")
.RowNumbers = False
.FillAdjacentFormulas = False
.PreserveFormatting = True
.RefreshOnFileOpen = False
.BackgroundQuery = True
.RefreshStyle = xlInsertDeleteCells
.SavePassword = False
.SaveData = True
.AdjustColumnWidth = True
.RefreshPeriod = 0
.PreserveColumnInfo = True
.ListObject.DisplayName = "Tableau_questions"
.Refresh BackgroundQuery:=False
End With
Sheets("clean").Select
Application.CutCopyMode = False
With ActiveSheet.ListObjects.Add(SourceType:=0, Source:= _
"OLEDB;Provider=Microsoft.Mashup.OleDb.1;Data Source=$Workbook$;Location=clean;Extended Properties=""""" _
, Destination:=Range("$A$1")).QueryTable
.CommandType = xlCmdSql
.CommandText = Array("SELECT * FROM [clean]")
.RowNumbers = False
.FillAdjacentFormulas = False
.PreserveFormatting = True
.RefreshOnFileOpen = False
.BackgroundQuery = True
.RefreshStyle = xlInsertDeleteCells
.SavePassword = False
.SaveData = True
.AdjustColumnWidth = True
.RefreshPeriod = 0
.PreserveColumnInfo = True
.ListObject.DisplayName = "Tableau_clean"
.Refresh BackgroundQuery:=False
End With
End Sub
And how i tried to call it in B
Call LoadQueries