excel - Create UDF in VBA Generated Workbook -


i'm building application in vba parse machine generated file. part of project need convert machine format integers since fixed width columns don't accommodate negative numbers. used macro recorder parse text file:

workbooks.opentext filename:= _     *file name here*, origin:= _     437, startrow:=1, datatype:=xlfixedwidth, fieldinfo:=array(array(0, 2), _     array(6, 2), array(10, 2), array(14, 2), array(19, 2), array(25, 2), array(27, 2), array(34 _     , 2), array(39, 2), array(43, 2), array(44, 2), array(52, 2)), trailingminusnumbers:= _     true 

but creates new workbook since it's opening new file. problem need run udf on final column converts fixed width value integer. example, suppose final column 0000000e , know e means last digit 5 , number negative. udf converts accordingly:

public function convertcodetointeger(inputstring string) long   if inputstring <> vbnullstring     select case right(inputstring, 1)         case "e" 'negative 5             convertcodetointeger = -1 * (left(inputstring, len(inputstring) - 1) & 5)          case else 'error case'             msgbox ("an error has occurred.")             end     end select else     convertcodetointeger = vbnullstring end if  end function  private sub testconvertcodetointeger()  debug.print convertcodetointeger("000001e")  end sub 

but since file open in new workbook can't access udf. there easy way use vba make udf available new workbook? either directly copying function code new workbook's module using vba somehow or accessing original code? or there way open text file in current workbook instead?

this needs portable using personal workbook isn't option.

record macro , import text file using data->from text instead. import in current workbook.


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 -