Hello folks

I've created an Excel to Word export engine in a model used regularly at work, that pulls information and tables from various tabs in the Excel model and compiles this into a range to export to Word. The export itself so far is generally working fine, it opens the Word document and uses a series of bookmarks that I've set up in the Word document to link to a series of ranges in the Excel model.

The problem I'm faced with, however, is updating the table of contents at the start of the Word document. I'm not as familiar with Word as I am with Excel, but I understand that the table is created by identifying lines within the text of the document that are set up with the styles 'Header1', 'Header2' etc. In this model, the headers for each section are generated in the Excel model so when they're being copied and pasted into the Word doc they don't have these styles. The reason why I've set it up this way is because the document can have any combination of up to 10 different sections of text and tables, and several of them can also then have several sub-sections (dependent on the user's requirements). I've set the Excel model up to number the sections required.

This is an example of the VBA code I'm using to paste in each section:

Please Login or Register  to view this content.
where 'xlRng1' is the name of a range in the Excel model, and 'wdRng1' is the corresponding bookmark in the Word document.

Is it possible to tell Word to change the style of a pasted range, and if so how? I tried adding this line of code after the PasteAnd Format line but got a 400 error message:

Please Login or Register  to view this content.
where 'wdDoc' is
Please Login or Register  to view this content.
Any help is, as ever, gratefully received

Many thanks
Kenny