|
-
Aug 9th, 2023, 01:36 PM
#1
Thread Starter
Addicted Member
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
-
Aug 9th, 2023, 04:22 PM
#2
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?
-
Aug 10th, 2023, 02:52 AM
#3
Thread Starter
Addicted Member
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)
-
Aug 10th, 2023, 04:07 AM
#4
Re: Adding text to bookmarks in a word doc without word automation
to hunt a species to extinction is not logical !
since 2010 the number of Tigers are rising again in 2016 - 3900 were counted. with Baby Callas it's 3901, my wife and I had 2-3 months the privilege of raising a Baby Tiger.
-
Aug 11th, 2023, 11:05 AM
#5
Thread Starter
Addicted Member
Re: Adding text to bookmarks in a word doc without word automation
 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.
-
Feb 20th, 2025, 11:18 AM
#6
Thread Starter
Addicted Member
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.
Tags for this Thread
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|