Results 1 to 2 of 2

Thread: [RESOLVED] Sudden problem with automating Word

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Sep 2018
    Posts
    160

    Resolved [RESOLVED] Sudden problem with automating Word

    Hi

    When I try use this code:

    Code:
            Dim jobsheet As String = "C:\projects\Mydoc.docx"
    
            Dim oword As Object
            Dim odoc As Object
           
    
            oword = CreateObject("Word.Application")
            odoc = oword.Documents.Add(jobsheet)
    
            odoc.Bookmarks("mybookmark").Range.Text = "Some text"
    
            odoc.SaveAs("C:\projects\Mydoc-edited.docx")
    
         
            odoc = Nothing
            oword.Quit()
            oword = Nothing

    I'm getting this error message:




    I know the code was working earlier, and I've not changed any settings in Word, so this has got me stumped.

    I've tried the code on another PC (which uses VS2019) and it works OK, and one of my colleagues has tried it via hsi copy of VS2022, so it seems to be something in Word. I'm using Office 365 (2016) v2207.

    Trust Centre settings for Macros and ActiveX are set to 'allow all'. I've tried explicitly setting the Inetcache folder as a trusted location, but Word won't let me do this for reasons of 'security'.

    What REALLY bugs me is that this was working fine earlier this morning. I can't see that Word has had an update, but something has obviously changed.

    Can anyone suggest how I can get some automation working again? I feel like I'm banging my head against the wall at the moment.

  2. #2

    Thread Starter
    Addicted Member
    Join Date
    Sep 2018
    Posts
    160

    Re: Sudden problem with automating Word

    I finally found a solution to this, so I'm posting in case this helps someone.


    All I had to do was clear the contents of this folder:


    C:\Users\(my username)\AppData\Local\Microsoft\Windows\INetcache\Content.Word


    Once that was done, no more security messages!

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