Adding text to bookmarks in a word doc without word automation
Hi
I've got a word doc with several bookmarks. I use a vb.net program to add text to some bookmark locations in the doc, save it as a pdf, and then save the doc to a new location.
I need the program to run as a scheduled task under a certain login account. I've got the task launching and the program working under my login OK, but it fails to do any word automation when I use the account I need to run it with. I suspect an issue with using Office 365, as the login I need to use doesn't have a 365 account - I thought I could use my creds on the 365 login, but it isn't working.
So, I need to find an alternative to Word automation for adding text to bookmarks in a word doc.
This is the sort of thing I currently do:
Code:
Dim oWord As Word.Application
Dim oDoc As Word.Document
oDoc = oWord.Documents.Open(filename)
oDoc.Bookmarks(bookmark_name).Range.Text = "Text I want to use"
oDoc.SaveAs(output_file)
Call oDoc.SaveAs2(pdf_name, 17)
oDoc = Nothing
oWord.Quit()
oWord = Nothing
I also have to use some code with word.range with one bookmark to get bold and italics to work, but this is essentially it.
I'm looking for a simple way to replicate the above without using Word automation. Can anyone suggest a good route for me to explore please?
Cheers
Re: Adding text to bookmarks in a word doc without word automation
One possible way:
https://support.syncfusion.com/kb/ar...nt-in-c-vb-net
It might help if we knew where the documents you want to edit are saved, and in what format.
Are they on your computer hard drive, or Microsoft's OneDrive or other storage location?
Are they .docx or .doc files?
Re: Adding text to bookmarks in a word doc without word automation
Thanks - I'll have a look at that, but I suspect there's going to be a fee at some stage and I was hoping for a free solution.
I've also found some stuff online about editing the XML directly, so I'm going to give that a go too!
To answer your queries, the files are on the local network and are .doc (so I'm going to have to convert to .docx in order to edit the xml I expect)
Re: Adding text to bookmarks in a word doc without word automation
Re: Adding text to bookmarks in a word doc without word automation
Quote:
Originally Posted by
ChrisE
Thanks for that link - I've got the xml editing idea to work OK for plain text, but it looks like it's going to be a bit of a faff for changing formatting, so I'll check this out.
Re: Adding text to bookmarks in a word doc without word automation
Quick follow up - I don't recall how I resolved this last time, but a similar issue came up again today and I found my own post when googling for an answer!
In case I get this again in the future, I thought I'd post this URL which helped:
https://stackoverflow.com/questions/...scheduled-task
It's the bit where you need to create Desktop folders which solved it.