In this code I am downloading and opening a CSV file from google trends (I call that part one). Hereafter the data is split into two columns and a line graph is made (I call that part two). If the code are to work for you, you'll have to follow the instructions given in the start of the code and putting log-in credentials into the code.
My problem is that the code works just fine when I am stepping through the whole thing using F8. Then the CSV-file/workbook is opened in the line: Invokepattern.Invoke. Part one also works when run seperately.
It does however NOT work when followed by more code in the form below nor if I split up the two parts and call the two subs seperately.
The problem/error occurs in the line in the beginning of part two of the code. The error message is: 'Subscript out of range'. The error makes sense since the csv-file/workbook is not open nor active.
The weird thing here is that when I then press debug and the debugger highlights where the error is found the CSV-file/workbook is opened!
Furthermore! I have found that if I force the code to debug after part one using the line of code: 'Stop', the CSV-file/workbook is then again opened!
Below is the code (Change Format - Menu is an add-in of my own. I have tried both with an without reference to it):
Bookmarks