Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 08-19-2021, 04:56 PM
donlincolnmsof donlincolnmsof is offline Paste number from memory. Windows 7 64bit Paste number from memory. Office 2003
Advanced Beginner
Paste number from memory.
 
Join Date: Oct 2011
Posts: 36
donlincolnmsof is on a distinguished road
Default Paste number from memory.

Hello

I have the following macro where it searched for the number "213-709-8116". This number is hard coded in the macro.

I’m looking for a macro where when I copy the number to the memory and when I press the hot key to run the macro, then it SHOULD PASTE WHAT’S IN THE MEMORY and then search for that number.



How can this be done

Any help will greatly appreciated.

Thanks.


Sub Macro3()
'
' Macro3 Macro
' Macro recorded 8/19/2021 by don
'
Selection.Find.ClearFormatting
With Selection.Find
.Text = "213-709-8116"
.Replacement.Text = "RECORD BEGINS"
.Forward = True
.Wrap = wdFindContinue
.Format = True
.MatchCase = False
.MatchWholeWord = False
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False
End With
Selection.Find.Execute
Selection.HomeKey Unit:=wdLine
Selection.MoveUp Unit:=wdScreen, Count:=1
End Sub
Reply With Quote
  #2  
Old 08-19-2021, 05:41 PM
Guessed's Avatar
Guessed Guessed is online now Paste number from memory. Windows 10 Paste number from memory. Office 2016
Expert
 
Join Date: Mar 2010
Location: Canberra/Melbourne Australia
Posts: 3,966
Guessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant future
Default

I found this link to help late-bind the clipboard object Office VBA Tips: Late Binding MSForms.DataObject to access the ClipBoard from VBA.

Adapting your code to incorporate this as a function results in the following. I'm not sure what you think your replace code is meant to do but it doesn't actually replace anything.
Code:
Sub FindReplaceClip()
  Dim sFind As String
  sFind = funClipText
  With Selection.Find
    .ClearFormatting
    .Text = sFind
    .Replacement.Text = "RECORD BEGINS"
    .Forward = True
    .Wrap = wdFindContinue
    .Format = True
    .MatchCase = False
    .MatchWholeWord = False
    .MatchWildcards = False
    .MatchSoundsLike = False
    .MatchAllWordForms = False
    .Execute
  End With
  Selection.HomeKey Unit:=wdLine
  Selection.MoveUp Unit:=wdScreen, Count:=1
End Sub

Function funClipText() As String
  Dim MyClip As Object, sFind As String
  Set MyClip = CreateObject("new:{1C3B4210-F441-11CE-B9EA-00AA006B1A69}")
  MyClip.GetFromClipboard
  funClipText = MyClip.GetText(1)
End Function
__________________
Andrew Lockton
Chrysalis Design, Melbourne Australia
Reply With Quote
  #3  
Old 08-19-2021, 06:38 PM
donlincolnmsof donlincolnmsof is offline Paste number from memory. Windows 7 64bit Paste number from memory. Office 2003
Advanced Beginner
Paste number from memory.
 
Join Date: Oct 2011
Posts: 36
donlincolnmsof is on a distinguished road
Default

That worked!!

Thanks.
Reply With Quote
Reply

Thread Tools
Display Modes


Similar Threads
Thread Thread Starter Forum Replies Last Post
Paste number from memory. Paste number only suresh_070379 Excel 2 09-29-2016 04:56 AM
Paste number from memory. Tab 'muscle memory'? markg2 Excel 1 01-09-2015 09:12 AM
Speed dial Copy & Paste Keyboard Memory foneunlocker Word 5 03-12-2014 08:39 PM
Old Age = Loss Of Memory oldtrout PowerPoint 0 01-02-2012 12:50 PM
Power Point copy-paste number list to RTF editor himanshu PowerPoint 0 02-22-2010 12:56 AM

Other Forums: Access Forums

All times are GMT -7. The time now is 03:30 PM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2024, vBulletin Solutions Inc.
Search Engine Optimisation provided by DragonByte SEO (Lite) - vBulletin Mods & Addons Copyright © 2024 DragonByte Technologies Ltd.
MSOfficeForums.com is not affiliated with Microsoft