ms access - vba ".find" stopped working -


currently code runs no error message not make requested replacement:

private sub testingbutton_click()      dim rngfound range     dim filetoprocess word.document     dim wordinstance object      set wordinstance = createobject("word.application") 'for these tests close word first.     set filetoprocess = wordinstance.documents.open("c:\sarah\junk\attach.doc")     wordinstance.activedocument.range.select 'gets whole document     toolbox.setupfind (wordinstance.activedocument.range)     wordinstance.activedocument.range.find         .text = "rock"         .replacement.text = "found it!"         .execute     end  end sub 

in toolbox module:

 public function setupfind(byref rngpassed word.range)     rngpassed.find       .clearformatting       .replacement.clearformatting       .text = ""       .replacement.text = ""       .forward = true       .wrap = wdfindcontinue       .format = false       .matchcase = false       .matchwholeword = false       .matchwildcards = false       .matchsoundslike = false       .matchallwordforms = false       .execute     end  end function 

the code above test database created troubleshooting. destination access form purpose extract information set of documents, , place information in database. working fine. stopped working after particularly spectacular crash. tried remove label while form in break mode. (i know,... deep regret) couldn't close access ctrl-break. wierdest part similar code no longer works in back-up copies of database either.

here things i've tried haven't worked:

re-import objects new database.similarly, rebuild backend database. break form's code (a couple thousand lines) modules. copy code notepad, save it, create button in new empty database. recreate subs & functions typing, once exist, paste in code wordpad. reset form's references, include msword. make brand new form in new database 1 button has displayed code. use defined range: started when got persistent error in rngtosearch.find.execute findtext:="reason". error highlighted .find , said 'argument not optional.' among other things, switched selection rather defined range in attempts isolate problem. working range rather selection need end again.

possibly relevant observations:

other forms in same database lots of backend code work fine. other routines in same form. 1 document open. far can tell, there's nothing unusual document. have tried multiple documents. text find exists in document, outside of table.

things have worked, might clues: in word straight up, no code, no nothing, use 'find' select targeted word. wordinstance.activedocument.range.text = replace(wordinstance.activedocument.range.text, "rock", "found it!"). trouble is, need again way more complex replace can handle.

specify scope replacement(s). code worked me access 2010 change in testingbutton_click() ...

'.execute .execute replace:=wdreplaceall 

toolbox.setupfind calls .execute. since find , replacement text both empty strings @ point , no scope specified, .execute doesn't cause harm ... doesn't seem useful either.


Comments

Popular posts from this blog

routing - AngularJS State management ->load multiple states in one page -

python - GRASS parser() error -

Swift game error message -