To create all the titles or subtitles of a text at once?

Hi

Is there a way to create all the titles or subtitles of a text at once or do we have to do it manually one by one?

Thanks