Simply you need to replace ThisWorkbook by ActiveWorkbook in most places.
ThisWorkbook
ActiveWorkbook