Spain to Croatia Train
Trains from Spain to Croatia are one of the least popular ways of travelling between these two countries. There are no direct trains, all departures require several train changes and hours of waiting time in between. Also, it is not possible to buy a ticket for the entire distance from Spain to Croatia, but you will need to make your own combination of journeys if your goal is to use the train as much as possible.
Although travelling from Barcelona to Zagreb is popular, there is no train departure connecting these two cities. You would have to get to the cities such as Zurich or Milan first in order to continue your journey. Also, it is very likely that you would need to travel part of the route by bus on some of the departures.
However, travelling by train from Spain to Croatia is definitely not a good idea, other means of transport such as buses and planes will save you both money and time.
Barcelona – Dubrovnik
Travelling from Barcelona to Dubrovnik is one of the most popular routes, still, there are no trains connecting these two cities. Even if you somehow make it by train from Barcelona to Zagreb, the farthest you can get by train is to Split. The railway in Croatia stops in Split so there is no further train connection to Dubrovnik. In that case, consider alternative options to get from Split to Dubrovnik.