Option Explicit
#If Win64 And VBA7 Then 'si version Excel 2010 64 bits
Declare PtrSafe Function FindWindow Lib "user32.dll" Alias "FindWindowA" ( _
ByVal lpClassName As String, _
ByVal lpWindowName As String) As Long
Declare PtrSafe Function ShellExecute Lib "shell32.dll" Alias "ShellExecuteA" ( _
ByVal hwnd As Long, _
ByVal lpOperation As String, _
ByVal lpFile As String, _
ByVal lpParameters As String, _
ByVal lpDirectory As String, _
ByVal nShowCmd As Long) As Long
Declare PtrSafe Function SendMessage Lib "user32.dll" Alias "SendMessageA" ( _
ByVal hwnd As Long, _
ByVal wMsg As Long, _
ByVal wParam As Long, _
ByRef lParam As Any) 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
#Else 'si autre version
Declare Function FindWindow Lib "user32.dll" Alias "FindWindowA" ( _
ByVal lpClassName As String, _
ByVal lpWindowName As String) As Long
Declare Function ShellExecute Lib "shell32.dll" Alias "ShellExecuteA" ( _
ByVal hwnd As Long, _
ByVal lpOperation As String, _
ByVal lpFile As String, _
ByVal lpParameters As String, _
ByVal lpDirectory As String, _
ByVal nShowCmd As Long) As Long
Declare Function SendMessage Lib "user32.dll" Alias "SendMessageA" ( _
ByVal hwnd As Long, _
ByVal wMsg As Long, _
ByVal wParam As Long, _
ByRef lParam As Any) 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
#End If
Const SW_NORMAL As Long = 1
Const WM_SETTEXT As Long = &HC
Sub Open_StikyNot()
Dim StikyNot_Window As Long, start_doc
Dim StikyNot_Note_Window As Long
Dim DirectUIHWND_Window As Long
Dim CtrlNotifySink_Window As Long
Dim Montexte_Window As Long
Dim Montexte As String
Dim t As Single
Montexte = Worksheets("Feuil1").Range("A1").Text
StikyNot_Window = FindWindow(vbNullString, "Pense-bête")
start_doc = ShellExecute(StikyNot_Window, "open", "C:\Windows\System32\StikyNot.exe", 0, 0, SW_NORMAL)
If start_doc = 2 Or start_doc = 3 Then Exit Sub
Do
DoEvents
StikyNot_Note_Window = FindWindow("Sticky_Notes_Note_Window", "Pense-bête")
Loop Until StikyNot_Note_Window > 2
t = Timer
Do While Timer < t + 0.5: DoEvents: Loop
DirectUIHWND_Window = FindWindowEx(StikyNot_Note_Window, 0&, "DirectUIHWND", vbNullString)
CtrlNotifySink_Window = FindWindowEx(DirectUIHWND_Window, 0&, "CtrlNotifySink", vbNullString)
Montexte_Window = FindWindowEx(CtrlNotifySink_Window, 0&, "{a64c3a50-b714-4e1f-a723-78db57a20a29}", vbNullString)
Call SendMessage(Montexte_Window, WM_SETTEXT, 0, Montexte)
End Sub
Bonjour Jean-Marie,Bonjour à tous
david84
Apparemment cela fonctionne avec un script powershell (utilisation de sendkeys)
Donc peut-être voir de ce côte pour VBA
(autre suggestion: tester avec l' objet Clipboard et coller le texte dans la note)
Option Explicit
#If Win64 And VBA7 Then 'si version Excel 2010 64 bits
Declare PtrSafe Function FindWindow Lib "user32.dll" Alias "FindWindowA" ( _
ByVal lpClassName As String, _
ByVal lpWindowName As String) As Long
Declare PtrSafe Function ShellExecute Lib "shell32.dll" Alias "ShellExecuteA" ( _
ByVal hwnd As Long, _
ByVal lpOperation As String, _
ByVal lpFile As String, _
ByVal lpParameters As String, _
ByVal lpDirectory As String, _
ByVal nShowCmd As Long) As Long
#Else 'si autre version
Declare Function FindWindow Lib "user32.dll" Alias "FindWindowA" ( _
ByVal lpClassName As String, _
ByVal lpWindowName As String) As Long
Declare Function ShellExecute Lib "shell32.dll" Alias "ShellExecuteA" ( _
ByVal hwnd As Long, _
ByVal lpOperation As String, _
ByVal lpFile As String, _
ByVal lpParameters As String, _
ByVal lpDirectory As String, _
ByVal nShowCmd As Long) As Long
#End If
Const SW_NORMAL As Long = 1
'cocher Microsoft Forms x.x Object Library
Sub Open_StikyNot2()
Dim StikyNot_Window As Long, start_doc
Dim StikyNot_Note_Window As Long
Dim Montexte As String
Dim oDat As DataObject
Montexte = Worksheets("Feuil1").Range("A1").Text
Set oDat = New DataObject
oDat.SetText Montexte
oDat.PutInClipboard
StikyNot_Window = FindWindow(vbNullString, "Pense-bête")
start_doc = ShellExecute(StikyNot_Window, "open", "C:\Windows\System32\StikyNot.exe", 0, 0, SW_NORMAL)
If start_doc = 2 Or start_doc = 3 Then Exit Sub
Do
DoEvents
StikyNot_Note_Window = FindWindow("Sticky_Notes_Note_Window", "Pense-bête")
Loop Until StikyNot_Note_Window > 2
SendKeys "^v"
SendKeys "{NUMLOCK}"
Set oDat = Nothing
End Sub
non Seven.Donc XP , non ? (cad sans UAC)
Private Declare Function Wow64DisableWow64FsRedirection Lib "kernel32.dll" (ByVal OldValue As Long) As Boolean
Private Declare Function Wow64RevertWow64FsRedirection Lib "kernel32.dll" (ByVal OldValue As Long) As Boolean
Private Declare Function Wow64EnableWow64FsRedirection Lib "kernel32.dll" (ByVal IsEnable As Boolean) As Boolean
Private Declare Function IsWow64Process Lib "kernel32.dll" (ByVal IsEnable As Boolean) As Boolean
Sub RunYourProgram()
Dim RetVal As Long
On Error Resume Next
Dim tmp As Long
RetVal = Wow64DisableWow64FsRedirection(tmp)
RetVal = ShellExecute(0, "open", "stikynot", "", "", SW_SHOWMAXIMIZED)
Wow64EnableWow64FsRedirection (True)
End Sub
Option Explicit
#If VBA7 And Win64 Then
Private Declare PtrSafe Function Wow64DisableWow64FsRedirection Lib "kernel32.dll" ( _
ByVal OldValue As Long) As Boolean
Private Declare PtrSafe Function Wow64RevertWow64FsRedirection Lib "kernel32.dll" ( _
ByVal OldValue As Long) As Boolean
Private Declare PtrSafe Function Wow64EnableWow64FsRedirection Lib "kernel32.dll" ( _
ByVal IsEnable As Boolean) As Boolean
Private Declare PtrSafe Function IsWow64Process Lib "kernel32.dll" ( _
ByVal IsEnable As Boolean) As Boolean
#Else
Private Declare Function Wow64DisableWow64FsRedirection Lib "kernel32.dll" ( _
ByVal OldValue As Long) As Boolean
Private Declare Function Wow64RevertWow64FsRedirection Lib "kernel32.dll" ( _
ByVal OldValue As Long) As Boolean
Private Declare Function Wow64EnableWow64FsRedirection Lib "kernel32.dll" ( _
ByVal IsEnable As Boolean) As Boolean
Private Declare Function IsWow64Process Lib "kernel32.dll" ( _
ByVal IsEnable As Boolean) As Boolean
#End If
Const SW_NORMAL As Long = 1
'cocher Microsoft Forms x.x Object Library
Sub RunYourProgram()
Dim RetVal As Long
Dim Montexte As String
Dim oDat As DataObject
Dim t As Single
Dim tmp As Long
Montexte = Worksheets("Feuil1").Range("A1").Text 'ne pas oublier de renseigner la cellule A1
Set oDat = New DataObject
oDat.SetText Montexte
oDat.PutInClipboard
'On Error Resume Next
RetVal = Wow64DisableWow64FsRedirection(tmp)
RetVal = ShellExecute(0, "open", "stikynot", "", "", SW_NORMAL)
Wow64EnableWow64FsRedirection (True)
t = Timer
Do While Timer < t + 0.5: DoEvents: Loop
SendKeys "^v"
SendKeys "{NUMLOCK}"
Set oDat = Nothing
End Sub
Private Declare Function Wow64RevertWow64FsRedirection Lib "kernel32.dll" (ByVal OldValue As Long) As Boolean
Private Declare Function IsWow64Process Lib "kernel32.dll" ( _
ByVal IsEnable As Boolean) As Boolean
Option Explicit
#If Win64 Then
Private Declare PtrSafe Function Wow64DisableWow64FsRedirection Lib "kernel32.dll" (ByVal OldValue As Long) As Boolean
Private Declare PtrSafe Function Wow64EnableWow64FsRedirection Lib "kernel32.dll" (ByVal IsEnable As Boolean) As Boolean
#Else
Private Declare Function Wow64DisableWow64FsRedirection Lib "kernel32.dll" (ByVal OldValue As Long) As Boolean
Private Declare Function Wow64EnableWow64FsRedirection Lib "kernel32.dll" (ByVal IsEnable As Boolean) As Boolean
#End If
Const SW_NORMAL As Long = 1
Sub RunYourProgram()
Dim RetVal As Long
Dim Montexte As String
Dim oDat As DataObject
Dim t As Single
Dim tmp As Long
Montexte = Worksheets("Feuil1").Range("A1").Text
Set oDat = New DataObject
oDat.SetText Montexte
oDat.PutInClipboard
#If Win64 Then
RetVal = ShellExecute(0, "open", "stikynot", "", "", SW_NORMAL)
#Else
RetVal = Wow64DisableWow64FsRedirection(tmp)
RetVal = ShellExecute(0, "open", "stikynot", "", "", SW_NORMAL)
Wow64EnableWow64FsRedirection (True)
#End If
If RetVal = 2 Or RetVal = 3 Then Exit Sub
t = Timer
Do While Timer < t + 0.3: DoEvents: Loop
SendKeys "^v"
SendKeys "{NUMLOCK}"
Set oDat = Nothing
End Sub
#If Win64 Then
RetVal = ShellExecute(0, "open", "stikynot", "", "", SW_NORMAL)
Option Explicit
#If Win64 Then
Private Declare PtrSafe Function Wow64DisableWow64FsRedirection Lib "kernel32.dll" ( _
ByVal OldValue As Long) As Boolean
Private Declare PtrSafe Function Wow64EnableWow64FsRedirection Lib "kernel32.dll" ( _
ByVal IsEnable As Boolean) As Boolean
Private Declare PtrSafe Function IsWow64Process Lib "kernel32" ( _
ByVal hProcess As Long, ByRef Wow64Process As Long) As Long
Private Declare PtrSafe Function GetCurrentProcess Lib "kernel32" () As Long
#Else
Private Declare Function Wow64DisableWow64FsRedirection Lib "kernel32.dll" ( _
ByVal OldValue As Long) As Boolean
Private Declare Function Wow64EnableWow64FsRedirection Lib "kernel32.dll" ( _
ByVal IsEnable As Boolean) As Boolean
Private Declare Function IsWow64Process Lib "kernel32" ( _
ByVal hProcess As Long, ByRef Wow64Process As Long) As Long
Private Declare Function GetCurrentProcess Lib "kernel32" () As Long
#End If
Const SW_NORMAL As Long = 1
'cocher Microsoft Forms x.x Object Library
Sub RunYourProgram2()
Dim RetVal As Long
Dim Montexte As String
Dim oDat As DataObject
Dim t As Single
Dim tmp As Long
Dim Ret As Long
Montexte = Worksheets("Feuil1").Range("A1").Text
Set oDat = New DataObject
oDat.SetText Montexte
oDat.PutInClipboard
IsWow64Process GetCurrentProcess, Ret
If Ret = 0 Then
RetVal = ShellExecute(0, "open", "stikynot", "", "", SW_NORMAL)
Else
RetVal = Wow64DisableWow64FsRedirection(tmp)
RetVal = ShellExecute(0, "open", "stikynot", "", "", SW_NORMAL)
Wow64EnableWow64FsRedirection (True)
End If
If RetVal = 2 Or RetVal = 3 Then Exit Sub
t = Timer
Do While Timer < t + 0.3: DoEvents: Loop
SendKeys "^v"
SendKeys "{NUMLOCK}"
Set oDat = Nothing
End Sub