It's difficult to really evaluate the performance of your code without a connection to your database, but there are some efficiencies you can use which may streamline the processing.
Some general Very Good Practices that are highly reccommended are:
- Always Use Option ExplicitAlways Use Option Explicit. This is just a good habit and should really be required.
- Always define and set references to all Workbooks and SheetsAlways define and set references to all Workbooks and Sheets. This even includes the code within your
Worksheet_Activatefunction. As a habit, you can follow your own code more easily and it's more easily portable to other functions. Plus, it can be very easy to mistake (assume) whichWorkSheetyou're referring to when the code is directing you to another. - Break up your code into smaller, logical blocks. This will make the main processing code read more compact as well as forcing you to have defined sets of data that now logically (and cleanly) pass from section to section.
So with those basics in mind, here are comments starting with your getWeather method:
You are wanting to restrict the caller to a specific place with the sted parameter. So enforce that restriction with a custom Type:
Enum Sted
Area1 = 4
Area2 = 6
Area3 = 8
End Type
Which changes the Sub declaration to
Public Sub getWeather(APIurl As String, place As Sted)
Then you can delete the If statement that sets up the internal value and always rely on the input parameter to be valid. It looks like the code creating the Shapes in this method is overwriting the information in the same Cells for all Weather. If that's not your intention, then the logic needs re-examining.
In the WorkSheet_Activate function, there are a few items to note:
When moving through a Recordset, it's a good habit to check for the end of the set using If Not(rs.BOF And rs.EOF) Then. Your code potentially gives an error if the Recordset is empty. This If statement will make sure to handle that instance as well. Additionally, to jump out of the loop (as in your Else block), simply write Exit Do. You can eliminate the endOfFile label and GoTo.
While these suggestions are not necessarily speed improvements, they will benefit your overall code clarity.