I have written a small routine in VBA originally using MS Word VBA but now in Access VBA. The sub( ) is triggered by a Button on a form. It Opens ‘Word’ and ‘Firefox’ copies the initial web page and pastes it into ‘Word’.
It works but for one thing. Once started it runs down as far as copying the web page then stops. I then have to click on the border of MS Access to get it moving again. Then Word is activated and the paste done. It is as though clicking Access returns the focus and so flushes the remaning events.
The Sleep( ) sub uses an API call and is in milliseconds. I did replace this with a a call to a subroutine using the same API but which also gave plenty of DoEvents. Nothing changed, I still had to click on the MSAccess Window to get it to finish. I have tried commenting out all SendKeys but it makes no difference.
The code is:
Dim WordID, FirefoxID
WordID = Shell("C:\Program Files\Microsoft Office\OFFICE11\WINWORD.EXE", vbNormalFocus) ' Activate Microsoft
AppActivate WordID, 1 ' Activate Microsoft Word.
FirefoxID = Shell("C:\Program Files\Mozilla Firefox\Firefox.exe", vbNormalFocus)
Sleep 2000
AppActivate FirefoxID, True
SendKeys "{ESC}", True
SendKeys "^a", True
SendKeys "^c", True
' --** Runs to here then need to click on border of access **--
AppActivate WordID, True ' Activate Microsoft Word.
SendKeys "^v", True
MsgBox "done"
Please could you let me know why this happens and, if there is one, suggest a solution.
Thank you for your time
It works but for one thing. Once started it runs down as far as copying the web page then stops. I then have to click on the border of MS Access to get it moving again. Then Word is activated and the paste done. It is as though clicking Access returns the focus and so flushes the remaning events.
The Sleep( ) sub uses an API call and is in milliseconds. I did replace this with a a call to a subroutine using the same API but which also gave plenty of DoEvents. Nothing changed, I still had to click on the MSAccess Window to get it to finish. I have tried commenting out all SendKeys but it makes no difference.
The code is:
Dim WordID, FirefoxID
WordID = Shell("C:\Program Files\Microsoft Office\OFFICE11\WINWORD.EXE", vbNormalFocus) ' Activate Microsoft
AppActivate WordID, 1 ' Activate Microsoft Word.
FirefoxID = Shell("C:\Program Files\Mozilla Firefox\Firefox.exe", vbNormalFocus)
Sleep 2000
AppActivate FirefoxID, True
SendKeys "{ESC}", True
SendKeys "^a", True
SendKeys "^c", True
' --** Runs to here then need to click on border of access **--
AppActivate WordID, True ' Activate Microsoft Word.
SendKeys "^v", True
MsgBox "done"
Please could you let me know why this happens and, if there is one, suggest a solution.
Thank you for your time