Есть простой вопрос:
Как макросе Ворда текстовой переменной присвоить содержание буфера обмена (тоже текст)?
Я весь инет перерыл.... а ответа не нашёл
Dim s As String
Selection.MoveLeft Unit:=wdCharacter, Count:=18, Extend:=wdExtend
Selection.Copy
s = Selection
MsgBox s
Declare Function OpenClipboard Lib "user32" (ByVal hWnd As Long) As Long
Declare Function GetClipboardData Lib "user32" (ByVal wFormat As Long) As Long
Declare Function CloseClipboard Lib "user32" () As Long
Declare Function GlobalLock Lib "kernel32" (ByVal hMem As Long) As Long
Declare Function lstrcpy Lib "kernel32" (ByVal lpString1 As Any, ByVal lpString2 As Any) As Long
Declare Function GlobalUnlock Lib "kernel32" (ByVal hMem As Long) As Long
Public Const MAXSIZE = 4096
Public Const CF_TEXT = 1
Function ClipBoard_GetData() As String
Dim hClipMemory As Long
Dim lpClipMemory As Long
Dim MyString As String
Dim RetVal As Long
If OpenClipboard(0&) = 0 Then
MsgBox "Cannot open Clipboard. Another app. may have it open"
Exit Function
End If
' Obtain the handle to the global memory
' block that is referencing the text.
hClipMemory = GetClipboardData(CF_TEXT)
If IsNull(hClipMemory) Then
MsgBox "Could not allocate memory"
GoTo OutOfHere
End If
' Lock Clipboard memory so we can reference
' the actual data string.
lpClipMemory = GlobalLock(hClipMemory)
If Not IsNull(lpClipMemory) Then
MyString = Space$(MAXSIZE)
RetVal = lstrcpy(MyString, lpClipMemory)
RetVal = GlobalUnlock(hClipMemory)
' Peel off the null terminating character.
MyString = Mid(MyString, 1, InStr(1, MyString, Chr$(0), 0) - 1)
Else
MsgBox "Could not lock memory to copy string from."
End If
OutOfHere:
RetVal = CloseClipboard()
ClipBoard_GetData = MyString
End Function
Dim MyData As DataObject
Sub bufer()
Dim y as string
Set MyData = New DataObject
MyData.GetFromClipboard
y = MyData.GetText
End Sub
Сейчас этот форум просматривают: нет зарегистрированных пользователей и гости: 68