Good Afternoon All
I'm pulling my hair out with an issue I have with an Excel to Word macro that populates a .dotx Word Template by copying the cell in Excel and going to the bookmark in Word to paste it, then saves it as a PDF, then creates an email with the PDF attached. The code I have previously used had worked fine up until last week when the raw data behind the tool changed and I had to do some messing about to reformat it all and add some columns in - I doubt this contributed towards it although its the only thing that has changed.
Now when I try to run the code, it gets to the .Selection.Paste line and then Word drops a 5097 error.
My issue is that when I restart the PC and try it, it will work for the first instance and paste it into the first bookmark, but drops the error at the second bookmark.
After that, it drops the 5097 at the first bookmark and a full restart is needed to get it to start again - so I think there is something across the applications that is breaking.
The rest of the code works fine so I'm at a loss as to what the problem is. Also I'm very amateur at this, although I did get it to work previously.
I've taken a lot of the fluff out of the code (like Usernames etc) and email body text, but I can't provide the Workbook as data that runs the frontsheet that populates this data is all sensitive information. I've attached an edited screenshot of the front page that it runs off so you can see that it pulls the data from A9 as a starting point then moves cells right to get their details for the Word attachment, then when its done it uses the I9 to choose the Word template to edit. The rest of the code works perfectly but I'm unsure if there is some Application issue across Office that is breaking when I run it first time.
Is there something glaringly obvious that I've missed up to the .Selection.Paste line that is causing an issue?
I did use the PasteSpecial previously and that worked but now it doesn't.
Willing to buy a pint for anyone that can help me get this running...
![]()
Please Login or Register to view this content.
Bookmarks