23izkool
02-08-2011, 04:27 PM
================= VBA CODE ==================
Sub RightClick()
Dim wshshell As Object
Dim i as Integer
Set wshshell = VBA.CreateObject("WScript.Shell")
wshshell.SendKeys ("+{F10}"), True
End Sub
================= VBA CODE ==================
Upon executing the above macro, a drop-down list appears (so the macro actually simulates a right-click on the mouse) --> What I am trying to do is to get the macro to choose 'Copy' in the list. I am able to do so by typing 'C'. However, when I tried to get the macro to do it by adding [SendKeys "C", True] in the macro, the letter 'C' is immediately fed into the excel sheet and appears as an entry 'C' in 1 of the cells in the sheet.
Thinking that it may be because SendKeys execute too fast such that the typing of C by sendkeys go faster than the drop-down list can detect, I added 'Application.wait Now +TimeValue ("00:00:01"), so the edited macro looks like below:
=================Edited VBA CODE ==================
Sub RightClick()
Dim wshshell As Object
Dim i as Integer
Set wshshell = VBA.CreateObject("WScript.Shell")
wshshell.SendKeys ("+{F10}"), True
' New Edit
Application.Wait Now + TimeValue("00:00:01")
SendKeys "C", True
End Sub
================= Edited VBA CODE ==================
However, this causes the macro to simply hang --> the drop-down list does not even show up. I have to end the macro to stop it.
Hope that some VBA gurus can help me with this!!!!!
SideNote:
I am trying to do the above because I ultimately intend to use this mouse --> rightclick --> select option in dropdown list macro on another independent software which can only copy entries by this method of mouseclicking (i.e. no option to choose 'Edit'--> Copy & Shortcuts like 'Ctrl-C' etc cannot be detected)
Sorry if writing too much --> cos hope to provide as much details as possible to get some help!!! Thanks a lot!!! Appreciate it!!!
Sub RightClick()
Dim wshshell As Object
Dim i as Integer
Set wshshell = VBA.CreateObject("WScript.Shell")
wshshell.SendKeys ("+{F10}"), True
End Sub
================= VBA CODE ==================
Upon executing the above macro, a drop-down list appears (so the macro actually simulates a right-click on the mouse) --> What I am trying to do is to get the macro to choose 'Copy' in the list. I am able to do so by typing 'C'. However, when I tried to get the macro to do it by adding [SendKeys "C", True] in the macro, the letter 'C' is immediately fed into the excel sheet and appears as an entry 'C' in 1 of the cells in the sheet.
Thinking that it may be because SendKeys execute too fast such that the typing of C by sendkeys go faster than the drop-down list can detect, I added 'Application.wait Now +TimeValue ("00:00:01"), so the edited macro looks like below:
=================Edited VBA CODE ==================
Sub RightClick()
Dim wshshell As Object
Dim i as Integer
Set wshshell = VBA.CreateObject("WScript.Shell")
wshshell.SendKeys ("+{F10}"), True
' New Edit
Application.Wait Now + TimeValue("00:00:01")
SendKeys "C", True
End Sub
================= Edited VBA CODE ==================
However, this causes the macro to simply hang --> the drop-down list does not even show up. I have to end the macro to stop it.
Hope that some VBA gurus can help me with this!!!!!
SideNote:
I am trying to do the above because I ultimately intend to use this mouse --> rightclick --> select option in dropdown list macro on another independent software which can only copy entries by this method of mouseclicking (i.e. no option to choose 'Edit'--> Copy & Shortcuts like 'Ctrl-C' etc cannot be detected)
Sorry if writing too much --> cos hope to provide as much details as possible to get some help!!! Thanks a lot!!! Appreciate it!!!