i'm writing code loops through textboxes of word document. these textboxes contain picture , caption. far, have written code gets caption textbox (which checked through msgbox caption).
i want copy caption, clear textbox of content, , paste old caption in (because i'm trying replace pictures updated one). however, keep getting error caption.copy , have no idea why. says caption "invalid qualifier." did digging around online haven't solved problem.
this most-related thing found: invalid qualifier error in visual basic 6.0
anyway, here's code. appreciated!
sub replaceimages() dim str string dim captiontag string dim imagetag string 'dim objshape variant type mismatch? dim filename string application.screenupdating = false application.displayalerts = false application.enableevents = false 'select directory match .png figure in document set selectfolder = application.filedialog(msofiledialogfolderpicker) selectfolder .title = "select directory" .allowmultiselect = false if .show <> -1 goto resetsettings spath = .selecteditems(1) & "\" end sfile = dir(spath & "*png") while sfile <> "" filename = sfile msgbox filename imagetag = betweenparentheses(filename) each objshape in activedocument.shapes if objshape.type = msotextbox set shapepicture = objshape str = objshape.textframe.textrange.text if instr(str, "(") > 0 captiontag = betweenparentheses(objshape.textframe.textrange) if captiontag = imagetag if instr(str, "figure") > 0 dim firstterm string dim secondterm string dim caption string firstterm = "f" secondterm = ")" dim startpos long dim stoppos long dim nextposition long nextposition = 1 caption = objshape.textframe.textrange.text until nextposition = 0 startpos = instr(nextposition, caption, firstterm, vbtextcompare) - 1 stoppos = instr(startpos, caption, secondterm, vbtextcompare) + 1 caption = mid$(caption, startpos + len(firstterm), stoppos - startpos - len(firstterm)) nextposition = instr(stoppos, caption, firstterm, vbtextcompare) loop caption.copy 'this error end if end if end if end if next objshape sfile = dir loop resetsettings: application.screenupdating = false application.displayalerts = false application.enableevents = false
the caption variable string while copy method applies objects in word object model.
you store text textframe caption variable:
caption = objshape.textframe.textrange.text and manipulate inside loop.
if want keep value of caption variable, assign value variable:
dim someothervariable string someothervariable = caption
Comments
Post a Comment