'Excel VBA code creates a new file and is not supposed to

I have 1 line of code that does something it's not supposed to and I can't really figure out why it's doing what it is doing.

here is the entire block of code from the function but only one line is doing something unexpected.

Sub MyTemplate()

Dim wordApp As Word.Application
Dim wordDoc As Word.Document
Dim wordMailMerge As Word.MailMerge
Dim wordPath As String
Dim excelPath As String
   
CurrentWorksheet = ActiveSheet.Name
excelPath = ThisWorkbook.Path & "\Sticker Maker.xlsm"
        
wordPath = ThisWorkbook.Path & "\Inventory Labels.docx"
Set wordApp = CreateObject("Word.Application")
Set wordDoc = wordApp.Documents.Open(wordPath)
Set wordMailMerge = wordDoc.MailMerge
wordApp.Visible = True
wordMailMerge.OpenDataSource Name:=excelPath, SQLStatement:="SELECT * FROM `'Barcode$'`"
wordMailMerge.Execute
wordDoc.Close


Set wordMailMerge = Nothing
Set wordDoc = Nothing
Set wordApp = Nothing
Sheets(CurrentWorksheet).Select

End Sub

The code seems to run fine until it gets to this statement

wordMailMerge.OpenDataSource Name:=excelPath, SQLStatement:="SELECT * FROM `'Barcode$'`"

for whatever reason when that statement runs it creates a file called input.xls in the directory above the location where the file running the code is located, and then tries to use that as the reference file for the mailmerge. (pop up window in word asking me for table to draw the data from, but it's empty)

this makes no sense because nowhere in my code is a file named "input.xls" referenced at all and the path I reference leads to a subfolder of where this file is created.

In other words it places it in a subfolder of the D drive for my computer and the macro is in a workbook running from a subfolder of that subfolder referencing itself.

for clarity sake this VBA code is running in the workbook that is supposed to be referenced for the word document's mailmerge. It seems as though the only reason the mailmerge doesn't execute is because it has changed the recipients list to the excel file it creates (input.xls) and that file is blank. But the variable excelPath is set to the correct file and location by the time that code runs so I really can't figure out what is going on.

P.S. there is more code than I included this is just a sub function of a much larger program the full code does start out by opening a file named "input file.xlsx" however after I copy and paste the data out of that file it is closed and there are no other references to it. The "input.xls" file doesn't even exist until the line of code I referenced in this post.



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source