|
楼主 |
发表于 2019-10-13 14:56
|
显示全部楼层
我参考了其他人的,代码如下,
Public Declare Sub keybd_event Lib "user32.dll" (ByVal bVk As Byte, ByVal bScan As Byte, ByVal dwFlags As Long, ByVal dwExtraInfo As Long)
Const KEYEVENTF_KEYUP = &H2
Const VK_TAB = &H9
Sub 按键切换()
Rem 模拟按alt+tab组合键
Call keybd_event(18, 0, 0, 0)
Call keybd_event(9, 0, 0, 0)
Call keybd_event(18, 0, KEYEVENTF_KEYUP, 0)
Call keybd_event(9, 0, KEYEVENTF_KEYUP, 0)
End Sub
这样就可以了。
但是我想要切换后,直接粘贴内容,可是第2个模拟键粘贴就无效了。
Public Declare Sub keybd_event Lib "user32.dll" (ByVal bVk As Byte, ByVal bScan As Byte, ByVal dwFlags As Long, ByVal dwExtraInfo As Long)
Const KEYEVENTF_KEYUP = &H2
Const VK_TAB = &H9
Sub 按键切换()
Rem 模拟按alt+tab组合键
Call keybd_event(18, 0, 0, 0)
Call keybd_event(9, 0, 0, 0)
Call keybd_event(18, 0, KEYEVENTF_KEYUP, 0)
Call keybd_event(9, 0, KEYEVENTF_KEYUP, 0)
End Sub
Sub 按键粘贴()
Rem 模拟按alt+tab组合键
Call keybd_event(17, 0, 0, 0)
Call keybd_event(86, 0, 0, 0)
Call keybd_event(17, 0, KEYEVENTF_KEYUP, 0)
Call keybd_event(86, 0, KEYEVENTF_KEYUP, 0)
End Sub
Sub 复制信息到其他地方()
Dim c As Range, t As String
Dim b, f As Integer
b = Cells.Find("邮箱").Column
f = Cells.Find("邮件内容").Column
If Selection.Value <> "" And Selection.Column > b - 1 And Selection.Column < f + 1 Then
For Each c In Selection
t = t & c & vbCrLf
Next
Set MyData = New DataObject
With MyData
.SetText t
.PutInClipboard
End With
Set MyData = Nothing
Cells(Selection.Row, Selection.Column + 1).Select
Call 按键切换
Call 按键粘贴
End If
If Selection.Column = f + 1 Then
For Each c In Selection
t = t & c & vbCrLf
Next
Set MyData = New DataObject
With MyData
.SetText t
.PutInClipboard
End With
Set MyData = Nothing
Cells(Selection.Row + 1, b).Select
Call 按键切换
Call 按键粘贴
End If
End Sub
第一次粘贴是可以的,到下次粘贴就无效了,这是为何?
|
|