excel vba - VBA: SendKeys "^c" seems to be copying to a different clipboard -
excel vba - VBA: SendKeys "^c" seems to be copying to a different clipboard -
i have code copies code excel , pastes , application. if code succeeds cursor in application automatically highlights text 0. have keyboard "ctrl-c", copies correctly in fact can paste 0 anywhere take manually using keyboard. within macro, using paste function or straight accessing clipboard doesn't give value, other values copied in macro @ prior line. surprisingly enough, if run macro stop (big reddish dot) in middle, after "ctrl-c" command, works fine, have run in 2 steps.
here's code:
public sub copyupctorms() dim upc string dim someinrms boolean dim integer dim sht worksheet set sht = worksheets(1) = 2 'while not isempty(cells(i, 5)) upc = sht.cells(i, 5).copy appactivate "retek - prd" sendkeys "%r" & "{tab}{tab}{tab}", true 'reset form sendkeys "^v" & "{enter}", true 'paste upc retek sendkeys "^c", true 'copies '0' global clipboard. '**i set stop here , run code in 2 portions "microsoft visual basic" lets you, , works, in 2 parts... sht.range("f10").value = clipboard_gettext '<--- pastes upc, not '0' 'wend end sub i've tried replacing sendkeys function similar same results (i can post code if needed), no avail. anyway, that's can think of now, took several hours figure out wrong...
i've written automation programme seems you've done , have had similar issues. think lastly sendkeys phone call , clipboard_gettext phone call happening in timing re-create function not having time finish before next phone call executes. how solved in application grabbing sleep function kernel32.dll (there article here: http://www.exceltrick.com/formulas_macros/vba-wait-and-sleep-functions/ - have declare differently 64 bit systems) placing declaration in place code can see (same module should fine - way @ top prior functions or subs):
declare sub sleep lib "kernel32" (byval dwmilliseconds long) and after each sendkeys call, can forcefulness code pause bit; since time in milliseconds, 1000 1 second. so, example, can call
sleep 500 and there half sec pause between next line of code beingness run. think may work you, because when set breakpoint (the reddish dot), have code stop, , run 1 time again manually, works, apparently. think may timing issue sleep can help out with. if that's issue, play sleep time maintain operation time minimum. luck.
vba excel-vba
Comments
Post a Comment