Results 1 to 6 of 6

Thread: Adding text to bookmarks in a word doc without word automation

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Sep 2018
    Posts
    160

    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

  2. #2
    PowerPoster jdc2000's Avatar
    Join Date
    Oct 2001
    Location
    Idaho Falls, Idaho USA
    Posts
    2,525

    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?

  3. #3

    Thread Starter
    Addicted Member
    Join Date
    Sep 2018
    Posts
    160

    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)

  4. #4
    PowerPoster ChrisE's Avatar
    Join Date
    Jun 2017
    Location
    Frankfurt
    Posts
    3,129

    Re: Adding text to bookmarks in a word doc without word automation

    is powershell an option ??
    see this....https://devblogs.microsoft.com/scrip...word-bookmark/
    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.

  5. #5

    Thread Starter
    Addicted Member
    Join Date
    Sep 2018
    Posts
    160

    Re: Adding text to bookmarks in a word doc without word automation

    Quote Originally Posted by ChrisE View Post
    is powershell an option ??
    see this....https://devblogs.microsoft.com/scrip...word-bookmark/
    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.

  6. #6

    Thread Starter
    Addicted Member
    Join Date
    Sep 2018
    Posts
    160

    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
  •  



Click Here to Expand Forum to Full Width