Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Declare Function OpenClipboard Lib "User32" (ByVal hwnd As Long) As Long
- Declare Function EmptyClipboard Lib "User32" () As Long
- Declare Function CloseClipboard Lib "User32" () As Long
- Declare Function SetClipboardData Lib "User32" (ByVal wFormat As Long, ByVal hMem As Long) As Long
- Declare Function GlobalAlloc Lib "Kernel32" (ByVal wFlags As Long, ByVal dwBytes As Long) As Long
- Declare Function GlobalLock Lib "Kernel32" (ByVal hMem As Long) As Long
- Declare Function GlobalUnlock Lib "Kernel32" (ByVal hMem As Long) As Long
- Declare Sub CopyMemory Lib "Kernel32" Alias "RtlMoveMemory" (Destination As Any, Source As Any, ByVal Length As Long)
- Sub BucleInfinito()
- Dim textoAleatorio As String
- Do
- ' Genera una palabra de 5 caracteres aleatorios
- textoAleatorio = GenerarTextoAleatorio(5)
- ' Coloca el texto aleatorio en el portapapeles
- CopiarAlPortapapeles textoAleatorio
- ' Espera un segundo antes de continuar
- Application.Wait Now + TimeValue("00:00:01")
- Loop
- End Sub
- Function GenerarTextoAleatorio(ByVal Longitud As Integer) As String
- Dim caracteres As String
- Dim i As Integer
- ' Define los caracteres permitidos para el texto aleatorio
- caracteres = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
- ' Genera el texto aleatorio
- Randomize
- For i = 1 To Longitud
- GenerarTextoAleatorio = GenerarTextoAleatorio & Mid(caracteres, Int((Len(caracteres) * Rnd) + 1), 1)
- Next i
- End Function
- Sub CopiarAlPortapapeles(ByVal Texto As String)
- Dim hGlobalMemory As Long
- Dim lpGlobalMemory As Long
- Dim RetVal As Long
- ' Abre el portapapeles
- OpenClipboard 0&
- ' Borra el contenido actual del portapapeles
- EmptyClipboard
- ' Obtén un identificador de memoria global para el texto
- hGlobalMemory = GlobalAlloc(&H2, Len(Texto) + 1)
- ' Bloquea la memoria global y copia el texto en ella
- lpGlobalMemory = GlobalLock(hGlobalMemory)
- CopyMemory ByVal lpGlobalMemory, ByVal StrPtr(Texto), Len(Texto)
- GlobalUnlock hGlobalMemory
- ' Coloca la memoria global en el portapapeles
- RetVal = SetClipboardData(&H1, hGlobalMemory)
- ' Cierra el portapapeles
- CloseClipboard
- End Sub
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement