excel - VBA msoFileDialogOpen sometimes loops twice -
i have function allows user select file using vba's msofiledialogopen. however, loops twice. other times try replicate bug , can't. here confused code:
public sub function4_fileexplorer() on error goto exitsub ' start file explorer select file containing data (simple gui, easier coding vfilename) ' aware loops (recursively?) twice, stops; problem becomes unreproducible. application.filedialog(msofiledialogopen) .allowmultiselect = false ' don't let user select multiple files (this prevents problems filling worksheet cells incorrectly) if .show ' if file selected (no need use / while loop; increase cpu usage) path = .selecteditems(1) end if end msgbox path ' tell user file selected; user can quit macro if wrong file selected cells(7, 2) = path ' put filename on active sheet (which should "parameters") exitsub: exit sub end sub
Comments
Post a Comment