Bad File Name when using Excel to find words in a Word Document -


i'm using code below loop through data on excel spreadsheet , open word document. want cycle through word document , find of words on excel sheet. works okay until try , find words on excel sheet , "bad file name" message. i've highlighted line below error occurs. i'm sure syntax error, don't know correct syntax is. help.......

    dim mydb() string     dim mycol() string     dim mydbcnt integer     dim mycolcnt integer     dim dbcnt integer     dim resrow integer     dim r integer     dim x integer     dim prevrow integer     resrow = 1     r = 5     x = 1     prevrow = 4      until len(trim(cells(r, 4))) + len(trim(cells(r, 5))) = 0         doevents         redim preserve mydb(1 x)         if (trim(cells(r, 4)) & "." & trim(cells(r, 5))) = (trim(cells(prevrow, 4)) & "." & trim(cells(prevrow, 5))) '           nothing         else             mydb(x) = trim(cells(r, 4)) & "." & trim(cells(r, 5))             x = x + 1         end if          r = r + 1         prevrow = prevrow + 1     loop      x = x - 1     mydbcnt = x     r = 5     x = 1      until len(trim(cells(r, 4))) + len(trim(cells(r, 5))) = 0         doevents         redim preserve mycol(1 x)         mycol(x) = trim(cells(r, 6))         r = r + 1         x = x + 1      loop      x = x - 1     mycolcnt = x      worksheets("results").activate     mylastrow = cells.find("*", [a1], , , xlbyrows, xlprevious).row     resrow = mylastrow      set wordapp = createobject("word.application")     set worddoc = wordapp.documents.open("r:\report web\sql doc.docx")     wordapp.visible = true     worddoc.activate      tmp = worddoc.name     dim j integer      dbcnt = 1      wordapp.selection         until dbcnt > mydbcnt             doevents             documents(worddoc).find    ***error occurs here                 .text = mydb(dbcnt)                 j = 0                  while .execute(forward:=true) = true                     doevents                     j = j + 1                 loop             end              if j > 0                 msgbox mydb(dbcnt) & " found " & j & " times."             end if             dbcnt = dbcnt + 1         loop   end 

find not valid property of document object. need use on either selection or range object. example:

dim rngfind word.range set rngfind = worddoc.content rngfind.find  end 

Comments

Popular posts from this blog

ruby - Trying to change last to "x"s to 23 -

jquery - Clone last and append item to closest class -

c - Unrecognised emulation mode: elf_i386 on MinGW32 -