vba - How to execute this Excel to XML function in a sub? -


can assist how can use function below converts data in excel file xml file in sub? when go create macro default has sub need have function. need able use maybe custom button on toolbar possibly or how can use spreadsheet need convert excel xml file?

public function exporttoxml(fullpath string, rowname _ string) boolean  on error goto errorhandler   dim colindex integer dim rwindex integer dim ascols() string dim oworksheet worksheet dim sname string dim lcols long, lrows long dim ifilenum integer   set oworksheet = thisworkbook.worksheets(1) sname = oworksheet.name lcols = oworksheet.columns.count lrows = oworksheet.rows.count   redim ascols(lcols) string  ifilenum = freefile open fullpath output #ifilenum  = 0 lcols - 1 'assumes no blank column names if trim(cells(1, + 1).value) = "" exit ascols(i) = cells(1, + 1).value next  if = 0 goto errorhandler lcols =  print #ifilenum, "<?xml version=""1.0""?>" print #ifilenum, "<" & sname & ">" = 2 lrows if trim(cells(i, 1).value) = "" exit print #ifilenum, "<" & rowname & ">"  j = 1 lcols      if trim(cells(i, j).value) <> ""        print #ifilenum, "  <" & ascols(j - 1) & "><![cdata[";        print #ifilenum, trim(cells(i, j).value);        print #ifilenum, "]]></" & ascols(j - 1) & ">"        doevents 'optional     end if next j print #ifilenum, " </" & rowname & ">" next  print #ifilenum, "</" & sname & ">" exporttoxml = true errorhandler: if ifilenum > 0 close #ifilenum exit function end function 

to convert sub run button change to:

public sub exporttoxml() 

this automatically change last line end sub.

fullpath , rowname no longer passed function-arguments, would, presumably, need read cells on worksheet, or perhaps 2 inputboxes.

the sub no longer return boolean value, whatever happens value have converted code within same sub (or possibly passed sub).


Comments

Popular posts from this blog

c++ - Creating new partition disk winapi -

Android Prevent Bluetooth Pairing Dialog -

php - joomla get content in onBeforeCompileHead function -