excel vba - number of characters in text form field causing a runtime error 13 (type mismatch) -


programming novice here. kindly given piece of vba code while enabled me export text form field data , radio button data word excel.

when macro runs, places selected output set of radio buttons in single excel worksheet , text output text form fields worksheet in same document. excel file .xlsm macro enabled.

the code works dream if txt responses provided relatively short, couple of sentences @ most. however, if run macro include 1 of longer text form fields responses (which includes 529 characters) results in runtime 'type mismatch' error (13). i'm guessing must exceeding kind of character limit? or format of text? properties on txt form field set 'unlimited' , 'regular text'. here code:

option explicit  sub exportresponsestoexcel()      dim arroptionbuttons() string     dim dicoptionbuttons object     dim dicformfields object     dim oinlineshape inlineshape     dim oinlineshapes inlineshapes     dim ooptionbutton optionbutton     dim oformfields formfields     dim oformfield formfield     dim col long     dim odoc document     dim xlapp object     dim xlwb object      set odoc = activedocument      if odoc nothing         msgbox "no document active.", vbexclamation         exit sub     end if      set oinlineshapes = odoc.inlineshapes      col = 0     if oinlineshapes.count > 0         redim arroptionbuttons(1 2, 1 oinlineshapes.count)         set dicoptionbuttons = createobject("scripting.dictionary")         dicoptionbuttons.comparemode = vbtextcompare         each oinlineshape in oinlineshapes             if oinlineshape.type = wdinlineshapeolecontrolobject                 if typename(oinlineshape.oleformat.object) = "optionbutton"                     set ooptionbutton = oinlineshape.oleformat.object                     if not dicoptionbuttons.exists(ooptionbutton.groupname)                         col = col + 1                         arroptionbuttons(1, col) = ooptionbutton.groupname                         if ooptionbutton.value = true                             arroptionbuttons(2, col) = ooptionbutton.caption                         end if                         dicoptionbuttons.add ooptionbutton.groupname, col                     else                         if ooptionbutton.value = true                             arroptionbuttons(2, dicoptionbuttons(ooptionbutton.groupname)) = ooptionbutton.caption                         end if                     end if                 end if             end if         next oinlineshape         if col > 0             redim preserve arroptionbuttons(1 2, 1 col)         end if     end if      set oformfields = odoc.formfields      if oformfields.count > 0         set dicformfields = createobject("scripting.dictionary")         dicformfields.comparemode = vbtextcompare         each oformfield in oformfields             dicformfields(oformfield.name) = oformfield.range.text         next oformfield     end if      on error resume next     set xlapp = getobject(, "excel.application")     on error goto 0     if xlapp nothing         set xlapp = createobject("excel.application")         xlapp.visible = true     end if      set xlwb = xlapp.workbooks.add(-4167) 'create xl workbook containing 1 worksheet      xlwb.activesheet         .range("a1").value = "form field name"         .range("b1").value = "form field text"         if oformfields.count > 0             .range("a2").resize(dicformfields.count).value = xlapp.transpose(dicformfields.keys)             .range("b2").resize(dicformfields.count).value = xlapp.transpose(dicformfields.items)         end if         .columns("a:b").autofit         .name = "form fields"     end      xlwb.worksheets.add         .range("a1").value = "question"         .range("b1").value = "response"         if col > 0             .range("a2").resize(col, 2).value = xlapp.transpose(arroptionbuttons)         end if         .columns("a:b").autofit         .name = "option buttons"     end      appactivate xlwb.name      set dicoptionbuttons = nothing     set dicformfields = nothing     set oinlineshape = nothing     set oinlineshapes = nothing     set ooptionbutton = nothing     set oformfield = nothing     set oformfields = nothing     set odoc = nothing     set xlwb = nothing     set xlapp = nothing  end sub 

any appreciated - cal


Comments

Popular posts from this blog

java - Static nested class instance -

c# - Bluetooth LE CanUpdate Characteristic property -

JavaScript - Replace variable from string in all occurrences -