1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75
| Option Explicit
#If Win64 Then 'si Excel 64 bits
Declare PtrSafe Function FindWindow Lib "user32.dll" Alias "FindWindowA" ( _
ByVal lpClassName As String, ByVal lpWindowName As String) As Long
Declare PtrSafe Function FindWindowEx Lib "user32.dll" Alias "FindWindowExA" ( _
ByVal hWnd1 As Long, ByVal hwnd2 As Long, ByVal lpsz1 As String, _
ByVal lpsz2 As String) As Long
Declare PtrSafe Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long)
#Else 'si Excel 32 bits
Declare Function FindWindow Lib "user32.dll" Alias "FindWindowA" ( _
ByVal lpClassName As String, ByVal lpWindowName As String) As Long
Declare Function FindWindowEx Lib "user32.dll" Alias "FindWindowExA" ( _
ByVal hWnd1 As Long, ByVal hwnd2 As Long, ByVal lpsz1 As String, _
ByVal lpsz2 As String) As Long
Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long)
#End If
Sub M_balance_repcpt()
'
' M_Balance_Repcpt
'
'
Sheets.Add
ActiveSheet.Name = "repcpt"
Sheets("Repcpt1").Select
Columns("A:A").Select
Selection.Copy
Sheets("repcpt").Select
Range("A1").Select
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
Application.CutCopyMode = False
ActiveWorkbook.Worksheets("repcpt").Sort.SortFields.Clear
ActiveWorkbook.Worksheets("repcpt").Sort.SortFields.Add Key:=Range("A1"), _
SortOn:=xlSortOnValues, Order:=xlDescending, DataOption:=xlSortNormal
With ActiveWorkbook.Worksheets("repcpt").Sort
.SetRange Range("A1:A1687")
.Header = xlNo
.MatchCase = False
.Orientation = xlTopToBottom
.SortMethod = xlPinYin
.Apply
End With
Dim wNotePad As Long, wEdit As Long, RetVal As Long
Dim Data As Range, Wsh As Object
Const Pause As Long = 200
RetVal = Shell("notepad", vbNormalFocus)
If RetVal = 2 Or RetVal = 3 Then Exit Sub
Sleep Pause
Set Data = Sheets("repcpt").Columns("A:A")
Data.Copy
Sleep Pause
Set Wsh = CreateObject("WScript.Shell")
Wsh.SendKeys "^c"
Sleep Pause
wEdit = FindWindowEx(wNotePad, 0&, "Edit", vbNullString)
Sleep Pause
Wsh.SendKeys "^v"
Sleep Pause
Application.CutCopyMode = False
Set Wsh = Nothing
End Sub |
Partager