Sticky Notes (Post It)

Claudy

XLDnaute Accro
Bonjour,
est il possible d'insèrer un Post It (Stycky Notes) sur mon bureau avec le contenu de la cellule "A1" ?
Merci d'avance,
Claudy
 

david84

XLDnaute Barbatruc
Re : Sticky Notes (Post It)

Comment générer un nouveau Post It ?
Ci-joint une solution à tester (toujours sans SendKeys) lorsque l'on veut générer plusieurs Post It (messages dans la colonne A) :
Code:
Option Explicit
#If VBA7 And Win64 Then
  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 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 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 Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long)
     
  Declare PtrSafe Function Wow64DisableWow64FsRedirection Lib "kernel32.dll" ( _
    ByVal OldValue As Long) As Boolean
  
  Declare PtrSafe Function Wow64EnableWow64FsRedirection Lib "kernel32.dll" ( _
    ByVal IsEnable As Boolean) As Boolean
     
  Declare PtrSafe Sub GetClientRect Lib "user32" _
  (ByVal HWnd As Long, lpRect As RECT)
  
  Declare PtrSafe Sub ClientToScreen Lib "user32" _
  (ByVal HWnd As Long, lpPoint As POINT)
  
  Declare PtrSafe Sub mouse_event Lib "user32" _
  (ByVal dwFlags As Long, ByVal dx As Long, ByVal dy As Long, _
  ByVal cButtons As Long, ByVal dwExtraInfo As Long)
                                        
  Declare PtrSafe Function SetCursorPos Lib "user32" _
  (ByVal x As Long, ByVal y As Long) As Long
#Else
  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 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 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 Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long)
     
  Declare Function Wow64DisableWow64FsRedirection Lib "kernel32.dll" ( _
    ByVal OldValue As Long) As Boolean
  
  Declare Function Wow64EnableWow64FsRedirection Lib "kernel32.dll" ( _
    ByVal IsEnable As Boolean) As Boolean
     
  Declare Sub GetClientRect Lib "user32" _
  (ByVal HWnd As Long, lpRect As RECT)
  
  Declare Sub ClientToScreen Lib "user32" _
  (ByVal HWnd As Long, lpPoint As POINT)
  
  Declare Sub mouse_event Lib "user32" _
  (ByVal dwFlags As Long, ByVal dx As Long, ByVal dy As Long, _
  ByVal cButtons As Long, ByVal dwExtraInfo As Long)
                                        
  Declare Function SetCursorPos Lib "user32" _
  (ByVal x As Long, ByVal y As Long) As Long
#End If

Const SW_NORMAL As Long = 1
Const WM_SETTEXT As Long = &HC
Const MOUSEEVENTF_LEFTDOWN = &H2
Const MOUSEEVENTF_LEFTUP = &H4
 
Type RECT
  left As Long
  top As Long
  right As Long
  bottom As Long
End Type

Type POINT
  x As Long
  y As Long
End Type

Sub Sticky_Note()
Dim Zone As RECT
Dim Pos As POINT
Dim New_note As Long
Dim StickyNot_Note_Window As Long
Dim DirectUIHWND_Window As Long
Dim CtrlNotifySink_Window As Long
Dim Montexte_Window As Long
Dim Montexte As String
Dim RetVal As Long
Dim tmp As Long
Dim Ligne As Long
Dim DerLig As Long

DerLig = Worksheets("Feuil1").Range("A" & Rows.Count).End(xlUp).Row
For Ligne = 1 To DerLig
  Montexte = Worksheets("Feuil1").Cells(Ligne, 1).Text
  If Ligne = 1 Then
    RetVal = Wow64DisableWow64FsRedirection(tmp)
    RetVal = ShellExecute(0, "open", "stikynot", 0, 0, SW_NORMAL)
    Wow64EnableWow64FsRedirection (True)
    If RetVal = 2 Or RetVal = 3 Then Exit Sub
    GoTo Trouver_fenetre_saisie
  Else
    New_note = FindWindow("Sticky_Notes_Note_Adornment", vbNullString)
    GetClientRect New_note, Zone
    
    Pos.x = Zone.left
    Pos.y = Zone.top
    
    ClientToScreen New_note, Pos
    
    SetCursorPos Pos.x, Pos.y
    mouse_event MOUSEEVENTF_LEFTDOWN + MOUSEEVENTF_LEFTUP, Pos.x, Pos.y, 0, 0
    Sleep 100
    
Trouver_fenetre_saisie:
    Do
      DoEvents
      StickyNot_Note_Window = FindWindow("Sticky_Notes_Note_Window", "Pense-bête")
    Loop Until StickyNot_Note_Window > 2
    Sleep 100
    
    DirectUIHWND_Window = FindWindowEx(StickyNot_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)
  End If
  SendMessage Montexte_Window, WM_SETTEXT, 0, ByVal Montexte
Next Ligne
End Sub
A+
 

Pièces jointes

  • StickyNote.xls
    67.5 KB · Affichages: 66
  • StickyNote.xls
    67.5 KB · Affichages: 81
  • StickyNote.xls
    67.5 KB · Affichages: 80
Dernière édition:

david84

XLDnaute Barbatruc
Re : Sticky Notes (Post It)

Bonjour,
je viens de m'apercevoir que le fichier de mon message précédent comportait des déclarations d'API uniquement fonctionnelles sur une version 64 bits.
Ci-joint le fichier modifié et donc également fonctionnel sur une version 32 bits.
A+
 

Pièces jointes

  • StickyNote.xls
    53 KB · Affichages: 64
  • StickyNote.xls
    53 KB · Affichages: 67
  • StickyNote.xls
    53 KB · Affichages: 77

MJ13

XLDnaute Barbatruc
Re : Sticky Notes (Post It)

Bonjour à tous

Merci David pour cette nouvelle version :). C'est très balèze pour la programmation :eek:.

Toi ou quelqu'un pourrait-il testé sur Win 64 bits et XL 32 ou 64 bits sur ma version en copiant le fichier C:\Windows\system32\StikyNot.exe vers C:\Program Files(x86)\ pour voir si cela fonctionne?
 

david84

XLDnaute Barbatruc
Re : Sticky Notes (Post It)

Bonjour Michel,
sur mon ordinateur (Windows7 et Excel 2010 64 bits) StikyNot.exe est placé dans le dossier System32.
Le déplacement de ce fichier dans un autre dossier est refusé.
De toutes les manières tu n'as pas l'obligation d'indiquer tout le chemin : Shell "StikyNot.exe" suffit (mais de toutes les manières s'il n'est pas possible de le changer de place -ce qui reste à vérifier- cela ne change rien).
A+
 
Dernière édition:

Staple1600

XLDnaute Barbatruc
Re : Sticky Notes (Post It)

Bonsoir à tous


MJ13
Extrait de du lien de mon message #12
The reason why we could not call stikynot is that Office 2007 is a 32-bit application and stikynot is a 64 bit application, if we directly call it the request to system32 will be redirected to folder Wow64, thus, the call fails.
Personnellement je ne préfére pas déplacer ou copier StikyNot.exe puisque le code proposé par David84 fonctionne sur un Seven 64bits.
 
Dernière édition:

MJ13

XLDnaute Barbatruc
Re : Sticky Notes (Post It)

Bonjour David, Jean-Marie.


Oui, mais cela n'empêche pas d'essayer :eek:, sinon, à quoi ça sert que le forum se décarcasse :eek:.

Sur un Windows 8.1 64 bit et XL 2007 32 bits, mon code a fonctionné :).
 

Staple1600

XLDnaute Barbatruc
Re : Sticky Notes (Post It)

Re

MJ13
Je préfère ne pas déplacer rien de qui se trouve dans System32 (ou dans Windows)
Et j'ai déjà essayé ton code (comme indiqué précédemment) , il ne fonctionne pas sur mon PC.
MJ13Error.png
Par ailleurs , j'ai du mal à comprendre la finalité de passer par Excel pour remplir un post-it.
(Pourquoi ne pas saisir directement dans le post-it plutôt que dans une cellule qui ensuite ira remplir un post-it par macro?)
Car au bout du compte il y a d'abord une saisie manuelle d'un string, donc autant la saisir directement dans l'endroit final, non ?
 
Dernière édition:

david84

XLDnaute Barbatruc
Re : Sticky Notes (Post It)

Bonjour,
Par ailleurs , j'ai du mal à comprendre la finalité de passer par Excel pour remplir un post-it.
(Pourquoi ne pas saisir directement dans le post-it plutôt que dans une cellule qui ensuite ira remplir un post-it par macro?)
Car au bout du compte il y a d'abord une saisie manuelle d'un string, donc autant la saisir directement dans l'endroit final, non ?
Pour avoir la réponse à cette question il faudrait que Claudy nous en précise les raisons. Mais vu la manière dont il suit le fil qu'il a initié...
A+
 

Discussions similaires

Réponses
2
Affichages
232
Réponses
5
Affichages
198

Statistiques des forums

Discussions
312 779
Messages
2 092 046
Membres
105 168
dernier inscrit
makari69