Pause code execution but let Excel work -
i making macro want following things:
open file.
wait till file fills data (this file uses cell formulae download data external database, download takes approx 15 seconds)
- after 20 seconds check if downloaded, if no, wait further 10 seconds (up minute total waiting).
- if downloaded, archive , close file.
the problem have stopping code execution time while letting formulae update in meantime - tried application.wait after reading @ msdn that:
the wait method suspends microsoft excel activity , may prevent performing other operations on computer while wait in effect. however, background processes such printing , recalculation continue."
but didn't work - wait stopped both code , data download. there way stop code while let other excel activity continue? i'd macro able run unattended possible have ran in middle of night.
edit: tried siddarth's answer , doesn't work me. code tried:
sub processfile() dim bbgwb workbook dim filepath string filepath = "c:\test\0900cet.xls" set bbgwb = workbooks.open(filepath) wait 60 filepath = "c:\test\archive\" if len(dir(filepath)) = 0 mkdir filepath else 'do nothing. end if filepath = "c:\test\archive\0900.xls" bbgwb.worksheets(1).range("a1:az200").copy bbgwb.worksheets(1).range("a1:az200").pastespecial xlpastevaluesandnumberformats bbgwb.worksheets(1).range("c142").value = bbgwb.saveas filename:=filepath, fileformat:=56 bbgwb.close thisworkbook.close end sub private sub wait(byval nsec long) nsec = nsec + timer while nsec > timer doevents wend end sub
0900cet.xls has formulae which, after opening it, autoupdate data (which want store , archive, that's why add whole copy/paste special part @ end). tested opening 0900cet.xls manually (all formulae updated after 17.3 seconds) , via code above (not single cell updated before file got archived.
i use sub created self
sub sample() ' '~~> ' wait 5 '<~~ wait 5 seconds. change applicable ' '~~> ' end sub private sub wait(byval nsec long) nsec = nsec + timer while nsec > timer doevents wend end sub
Comments
Post a Comment