excel - Using VB to allow the user to pick a folder which loads all of the files into a spreadsheet -


struggling above question.

i have code can load of files folder spreadsheet. need make user can pick folder rather path being defined in code.

below code have, guidance appreciated.

sub from_idpxml_to_excelreport()  on error goto errh dim mywb workbook, wb workbook set mywb = thisworkbook dim mypath  mypath = "file path here”  dim myfile myfile = dir(mypath & "*.xml")   dim t long, n long, row long, column long t = 2 n = 0  application.screenupdating = false   while myfile <> "" n = n + 1 set wb = workbooks.openxml(filename:=mypath & myfile) if n > 1 row = wb.sheets(1).cells.find(what:="*", searchorder:=xlbyrows,                      searchdirection:=xlprevious).row column = wb.sheets(1).cells.find(what:="*", searchorder:=xlbycolumns,    searchdirection:=xlprevious).column wb.sheets(1).range(cells(3, "a"), cells(row, column)).copy mywb.sheets(1).cells(t, "a") else wb.sheets(1).usedrange.copy mywb.sheets(1).cells(t, "a") end if wb.close false t = mywb.sheets(1).cells.find(what:="*", searchorder:=xlbyrows,  searchdirection:=xlprevious).row + 1 myfile = dir() loop      application.screenupdating = true   mywb.save exit sub errh: msgbox "no xml files in folder specified"  end sub 

thanks.

sure, replace:

mypath = "file path here”  

with:

mypath = getfolder() 

and include udf in module:

public function getfolder() string     dim fldr filedialog     dim sitem string     set fldr = application.filedialog(msofiledialogfolderpicker)     fldr         .title = "select folder"         .allowmultiselect = false         .initialfilename = application.defaultfilepath         if .show <> -1 goto nextcode         sitem = .selecteditems(1)     end nextcode:     getfolder = sitem & "\"     set fldr = nothing end function 

Comments

Popular posts from this blog

javascript - Jquery show_hide, what to add in order to make the page scroll to the bottom of the hidden field once button is clicked -

javascript - Highcharts multi-color line -

javascript - Enter key does not work in search box -