Highlight key words and paragraphs in all word documents in a set folder

  • I've made some amendments, but a lot of this is guess work.


  • Hi Roy,


    I'm getting run time error '429': Activex component can't create object, with line 15 of your code highlighted.


    I've referenced Microsoft Word 16.0 Object library as requested.


    Regards,


    Lee

  • Hi Roy,


    Now I get run-time error '-2147221020 (800401e4)': Automation error Invalid Syntax.


    The same line as previous is also highlighted.


    Regards,


    Lee

  • I made progress, you had a this symbol ( ' ) ('On Error Resume Next) On the previous line.

    I have removed the ' and now it runs down to line 41 of the code. For Each Word In appWd.ActiveDocument.Words is now highlighted.


    runtime error '13': Type mismatch


    Regards,


    Lee

  • Hi Roy,


    after a few hours of tweaking I have managed to get it to work, please see code below.

    However I am getting an intermitent run time error '462': The remote server machine does not exist or is unavailable, Set oDoc = Documents.Open(FileName:=sFldr & vFile) is highlighted on line 32.


    This runtime message will pop up but if i stop it and run the macro a second time it will work.


    I have a pdf to word macro running straight before it runs this macro. Do you think it might need a delay between macro's in order for it to carry out it's procedure?


    I am not sure why it is doing it, any ideas?


    Regards,


    Lee


  • Morning Roy,


    I have got it to work without converting the PDF's to word. MS word opens the PDF in word in the same format, the only problem I have now is I get a save as pop up box asking me which location i would like to save the .doc file to and I have got to press save every time.


    If I click cancel on the save as I get Run-time error '4198' Command failed. More than likely because I interupted the loop process.


    Below is what is highlighted at the very bottom of the script on the debug.


    Is it possible to amend the script to automatically save to the same location it opened the file without the save as box opening up.


    I feel that we are so close. :)


    Regards,


    Lee


    Code
    1. oDoc.Close SaveChanges:=True
  • I have on row 61, and it brings up the save as box. I don't wish to be prompted to save as every time it opens a file to highlight, I just want it to save to the location it opened the pdf from.


    Regards,


    Lee

  • What's happening is because it's opened the pdf in word, when it has finished it's highlighting action it is trying to then save as a word document.

    The save as dialouge box is opening up because it was not originally a word document, if that makes sense.


    Regards,


    Lee

  • Hi Roy,


    getting there. Is it possible to save the file name as the number 1 then increment by one on every save? i.e. 1 2 3 4 5 6 7

    The problem with your script is as it loops it can not save the same file name twice.


    Regards,


    Lee

  • Something like


    Code
    1. Dim iX As Integer
    2. ''/// within the Loop
    3. iX = iX + 1
    4. oDoc.SaveAs Filename:=ThisWorkbook.Path & Application.PathSeparator & iX, _
    5. FileFormat:=wdSaveFormat.wdFormatDocument

    Or


    Code
    1. oDoc.SaveAs Filename:=ThisWorkbook.Path & Application.PathSeparator & Format(Now, "hhmmss"), _
    2. FileFormat:=wdSaveFormat.wdFormatDocument
  • Hi Roy,


    I have used below which seems to of done the trick. It loops through keeping the original PDF file name before saving it as a word document.


    I tried your code to increment on 1 but it comes back with an error.


    Thanks for all your help.


    Regards,


    Lee


    Code
    1. Documents.Save NoPrompt:=True, _
    2. OriginalFormat:=wdOriginalDocumentFormat