excel - Batch Convert TDM files to XLS using Add-In that works 1 at a time -


1st time poster. goal: batch convert .tdm files in folder .xls using existing add-in adapting macro works 1 file @ time. (also open vba approach)

using existing add-in, single .tdm file converted single .xls workbook multiple sheets. need macro repeat same process doing instead of using prompt select single .tdm file, need automatically select , convert .tdm files in folder new .xls workbooks.

this part of multi-stage process.. , can't work, after trying various loops, mimicking other set-ups, , merging other code found on various community boards.

i have intermediate vba experience.. , believe i've been close solving it.. it's pro fix quickly/ easily.

fyi: .tdm files hold engineering data output produced testing equipment.

sub gettdm_addin()  'get tdm excel add-in  dim obj comaddin  set obj = application.comaddins.item("exceltdm.tdmaddin")  'obj.connect = true   'confirm importing "description" properties root  call obj.object.config.rootproperties.deselectall  call obj.object.config.rootproperties.select("description")   'show group count property  call obj.object.config.rootproperties.select("groups")   'select available properties group  call obj.object.config.groupproperties.selectall   'import custom properties  obj.object.config.rootproperties.selectcustomproperties = true  obj.object.config.groupproperties.selectcustomproperties = true  obj.object.config.channelproperties.selectcustomproperties = true   'let user choose file import  dim filename  filename = application.getopenfilename("tdm & tdms (*.tdm;*.tdms),*.tdm;*.tdms")  if filename = false  ' user selected cancel  exit sub  end if   'import selected file  call obj.object.importfile(filename)   'record down current workbook  dim workbook object  set workbook = activeworkbook   end sub 

thanks in advance.

below excel macro (vba script) wrote similar want do. converts directory of .tdms files equivalent .csv files. requires exceltdm add in (nitdmexcel_2015-0-0.exe) obtained @ http://www.ni.com/example/27944/en/. tested script in excel 2013 running on modest windows 7 pro machine converting 24 tdms files 120,000 rows each file. completed conversions without error in 2 minutes 30 seconds 7 seconds per file. please forgive hasty error handling , poor vba form.

sub converttdmstocsv() ' ' converttdms macro ' ' acts upon .tdms files in "source" directory, ' loading each 1 using exceltdm add in, ' deleting first sheet , saving ' remaining stream data 1 .csv file ' in "target" directory.  writes list of ' files converted in new sheet. ' ' tested work excel 2013 on windows 7 ' nitdmexcel_2015-0-0.exe obtained @ ' http://www.ni.com/example/27944/en/      dim sourcedir string, targetdir string, fn string, fnbase string     dim fso object, n long, resp integer, strnow string, newsheet object     dim tdmsaddin comaddin, importedworkbook object     set fso = createobject("scripting.filesystemobject")      set tdmsaddin = application.comaddins.item("exceltdm.tdmaddin")     tdmsaddin.connect = true     call tdmsaddin.object.config.rootproperties.deselectall     call tdmsaddin.object.config.channelproperties.deselectall     tdmsaddin.object.config.rootproperties.selectcustomproperties = false     tdmsaddin.object.config.groupproperties.selectcustomproperties = false     tdmsaddin.object.config.channelproperties.selectcustomproperties = false       'choose tdms source directory     application.filedialog(msofiledialogfolderpicker)         .title = "choose source directory of tdms files"         .allowmultiselect = false         .initialfilename = thisworkbook.path & "\"         .show         on error resume next         sourcedir = .selecteditems(1)         err.clear         on error goto 0     end     if dir(sourcedir, vbdirectory) = ""         msgbox "no such folder.", vbcritical, sourcedir         exit sub     end if      'choose csv target directory     application.filedialog(msofiledialogfolderpicker)         .title = "choose target directory csv files"         .allowmultiselect = false         .initialfilename = thisworkbook.path & "\"         .show         on error resume next         targetdir = .selecteditems(1)         err.clear         on error goto 0     end     if dir(targetdir, vbdirectory) = ""         msgbox "no such folder.", vbcritical, targetdir         exit sub     end if        fn = dir(sourcedir & "\*.tdms")     if fn = ""         msgbox "no source tdms files found.", vbinformation         exit sub     end if      resp = msgbox("begin conversion of tdms files?" & vbcrlf & sourcedir & vbcrlf & "to" & vbcrlf & targetdir, vbyesno, "confirmation")     if resp = vbno         msgbox "execution cancelled user."         exit sub     end if      set newsheet = thisworkbook.sheets.add(after:=thisworkbook.sheets(thisworkbook.sheets.count))     strnow = worksheetfunction.text(now(), "m-d-yyyy h_mm_ss")     newsheet.name = strnow     newsheet.cells(1, 1).value = "files converted on " & strnow     newsheet.cells(2, 1).value = "tdms source directory: " & sourcedir     newsheet.cells(3, 1).value = "csv target directory: " & targetdir       application.calculation = xlcalculationmanual     application.screenupdating = false     n = 5     while fn <> ""         fnbase = fso.getbasename(fn)          on error resume next         call tdmsaddin.object.importfile(sourcedir & "\" & fn, true)         if err             msgbox err.description, vbcritical             exit sub         end if         set importedworkbook = activeworkbook         application.displayalerts = false         importedworkbook.sheets(1).delete         importedworkbook.saveas filename:=targetdir & "\" & fnbase & ".csv", fileformat:=xlcsv         importedworkbook.close savechanges:=false         application.displayalerts = true          newsheet.cells(n, 1).value = fnbase         n = n + 1         fn = dir     loop     application.calculation = xlcalculationautomatic     application.screenupdating = true       set fso = nothing     set newsheet = nothing     set importedworkbook = nothing end sub 

Comments

Popular posts from this blog

java - How to specify maven bin in eclipse maven plugin? -

single sign on - Logging into Plone site with credentials passed through HTTP -

php - Why does AJAX not process login form? -