Runtime error 5
Runtime error 5
I am on Day one in learning Excel Macros. As per the tutorial I recorded the macros and tried to run it. (I have used the same file that they have provided in the tutorial and it is a .csv file)
But it showing me the following Error
Runtime Error
Invalid Procedure call or Argument
When I tried to debug it is showing as follows:

Need Help
-Thanks
I am not sure about the query that you are asking as I am completely Novice in this. Here is the link of the tutorial guru99.com/introduction-to-macros-in-excel.html
– Sree
Aug 26 at 13:05
What happens if you remove that line? Or comment out by placing ' in front of it.
– QHarr
Aug 26 at 13:10
1 Answer
1
You can set the CommandType property only if the value of the QueryType property for the query table or PivotTable cache is xlOLEDBQuery, which is enum 5.
This is not the case for your query. In fact, that line doesn't even exist in the source code. Perhaps you attempted to merge scripts? If so, be careful when merging connection code that the types are the same.
If you add in a debug line to get the QueryType
Debug.Print .QueryType
.Name = "receipts"
you will get the enum 6 back. You can look this up using the object explorer:

As would be expected from the connection specification:
ActiveSheet.QueryTables.Add(Connection:="TEXT;
By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.
superuser.com/questions/846166/… You can set the CommandType property only if the value of the QueryType property for the query table or PivotTable cache is xlOLEDBQuery. Is yours xlOLEDBQuery? Can you share the tutorial link? I guess if it works in the tutorial......
– QHarr
Aug 25 at 15:21