Forum Discussion
Berger1012
Apr 20, 2020Copper Contributor
VBA Error when creating power query with variables
I have a problem with VBA. I want to create a power query and I get this error: run-time error 1004, application or object-defined error. I really don't know how to fix it and would really hope that ...
JKPieterse
Apr 20, 2020Silver Contributor
Does the code work if the query of that name is not in the workbook?
Berger1012
Apr 20, 2020Copper Contributor
Thank you so much for your answer!
I just changed the variables to this:
Dim varName As Variant
varName = "appf us"
Dim varSource As Variant
varSource = "C:\Users\Thoma\Downloads\Neuer Ordner\appf.us.txt"
No I get the same error again. The debugger tells me, that the error occours in this line of the complete code:
.ListObject.DisplayName = varName
So I still think that the error has to be in the variable "varName" but I can't find a solution to fix it.
- JKPieterseApr 20, 2020Silver ContributorA listobject's name cannot contain spaces, that is the source of your error.
- Berger1012Apr 20, 2020Copper Contributor
Thank you for your answer!
I just changed the varibale varName to this:varName = "appf"
The space is now deleted but it still does not work. The error is also still the same but now the debugger tells me that the error occours in this line of the complete code:
.Refresh BackgroundQuery:=False
- JKPieterseApr 20, 2020Silver ContributorNow you've gotten to this stage you can go into the query and see which step causes an error. Stop the VBA macro first of course.