Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Microsoft Office > Other Office > Word VBA
|
Word VBA Discuss using VBA to program Word.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Word VBA section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old November 30th, 2006, 03:13 AM
Registered User
 
Join Date: Nov 2006
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default Paste from clipboard and start to search

Hallo I need help. I have edited a dictionary and for search word into this dictionary, I when the file Dictionary.doc start it must copy from clipboard a word, paste the same word in Dictionary.doc and begin to search in Dictionary.doc this word.
I edited this macro:
File Dictionary.doc in VBA ThisDocument I have stored:
Private Sub Document_Open()
    Application.Run MacroName:="ClipBoard_GetData"
End Sub

In a new module of file Dictionary.doc I have stored:
Declare Function OpenClipboard Lib "User32" (ByVal hwnd As Long) _
As Long
Declare Function CloseClipboard Lib "User32" () As Long
Declare Function GetClipboardData Lib "User32" (ByVal wFormat As _
Long) As Long
Declare Function GlobalAlloc Lib "kernel32" (ByVal wFlags&, 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 Function GlobalSize Lib "kernel32" (ByVal hMem As Long) _
As Long
Declare Function lstrcpy Lib "kernel32" (ByVal lpString1 As Any, _
ByVal lpString2 As Any) As Long

Public Const GHND = &H42
Public Const CF_TEXT = 1
Public Const MAXSIZE = 4096

Function ClipBoard_GetData()
    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

I must insert in Dictionary.doc also a macro that in automatic paste the clipboard data and begin to search clipboard data in the file Dictionary.doc.
I am not be able to make this macro please give me an help

paolo
:(

 
Old November 30th, 2006, 04:50 AM
Friend of Wrox
 
Join Date: Sep 2005
Posts: 812
Thanks: 1
Thanked 53 Times in 49 Posts
Default

Paolo

I guess you need to paste the data in the document and find the same

To paste the data

Selection.TypeText "SomeText"


and

to find a string

Selection.Find.Execute "om"

should work

Cheers
Shasur



http://www.vbadud.blogspot.com
 
Old November 30th, 2006, 09:31 AM
Registered User
 
Join Date: Nov 2006
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Thanks for a replay.
But where I put this?

Selection.TypeText "SomeText"
Selection.Find.Execute "om"

 
Old December 29th, 2006, 03:47 AM
GLM GLM is offline
Authorized User
 
Join Date: Dec 2006
Posts: 10
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Create a proc. "EditPaste" this proc will be triggered
 when a user paste something into the document

glm





Similar Threads
Thread Thread Starter Forum Replies Last Post
Paste Clipboard Image windows_mss BOOK: Professional JavaScript for Web Developers ISBN: 978-0-7645-7908-0 4 October 27th, 2008 01:47 PM
Clipboard bschleusner C# 2005 1 February 16th, 2007 08:20 AM
Is the clipboard empty? achinfish Excel VBA 1 July 15th, 2006 04:34 PM
the clipboard natmaster Java GUI 0 May 31st, 2004 02:16 PM
Saving to the clipboard xelepi Javascript How-To 2 November 7th, 2003 07:51 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.