excel - VBA: need to close window, only can close workbook -
i've set vba filter specific type of file , return filtered data (with 3 columns shown) in new worksheet. have 2 buttons in worksheet - 1 select file path, , other run filter on file in path (which in cell f7).
my issue haven't been able read selected file without opening it. fine, since it's quick process, command close file closes workbook, , leaves empty excel window open. workbook want open 1 i'm executing commands, 1 filtered results paste to. suggestions? i'm fine figuring out way window close, or execute process without window needing open in first place (this ideal).
public sub commandbutton2_click() b = application.getopenfilename() if b = false msgbox (" have not selected file!") else thisworkbook.worksheets("selectupdatefile").cells(7, 6).value = b msgbox ("your file has been selected. click filter button below generate moved nodes.") end if end sub sub autofilter() dim s string dim oapp object dim wb object dim ws object set oapp = createobject("excel.application") oapp.visible = true on error resume next set wb = oapp.workbooks.open(filename:=cells(7, 6)) on error goto 0 if not wb nothing 'specify worksheet name set ws = wb.worksheets(1) s = "ab" ws 'disable previous filters .autofiltermode = false 'apply new filter .range("$a$2:$k$100000").autofilter field:=1, criteria1:="=*move*", _ operator:=xland .range("$a$2:$k$100000").autofilter field:=7, criteria1:="=*%3e*", _ operator:=xland 'copy .range("a2:a100000").copy sheets("movednodes").range("a1").pastespecial xlpastevalues .range("b2:b100000").copy sheets("movednodes").range("b1").pastespecial xlpastevalues .range("g2:g100000").copy sheets("movednodes").range("c1").pastespecial xlpastevalues 'paste sheet2 end end if oapp.displayalerts = false oapp.workbooks.close msgbox ("done! click ok view moved nodes.") application.screenupdating = true sheets("movednodes").select end sub
you closing workbook in code.
oapp.workbooks.close
will close workbook , leave window open.
add oapp.quit
after closing workbook
Comments
Post a Comment