View Full Version : Macro to find copy and paste
wtf.ftw
05-14-2011, 07:00 PM
Hi,
I am trying to write a macro that will find copy and paste a text.
I need to find it in two parts.
1. Find the text on top of every page that is in the form of a barcode. which looks something like this "*WO-0012345*"
2. I need it to copy that text and then find another text that is right under it. the text is "Please keep this number for reference..." and then paste the copied order number there.
Another thing is that if i resize the frame with the barcode then it will show the order number too but i cant do that.
Can anybody pitch any ideas.
Thanks.
macropod
05-15-2011, 01:42 AM
This appears to be related to http://www.vbaexpress.com/forum/showthread.php?t=37371
Correct? If so, you're going to have trouble with the 'right under it' notion, as the "*WO-0012345*" is a frame (as is, I suspect, the "Please keep this number for reference") and these objects exist in a different relationship to ordinary directional concepts. None of this is trivial, so you need to specify clearly what you're trying to achieve.
wtf.ftw
05-15-2011, 01:24 PM
Yes it is.
What i am trying to achieve is that i need the order number in both a barcode format and a numerical format.
1. The font for the barcode actually has a numerical value under the barcode, but the frame needs to be increased in height to view the whole thing.
2. If that is not possible, then i want to copy the order number and paste it somewhere else on the page, it doesnt really matter where though.
macropod
05-15-2011, 03:40 PM
Try the following macro. You'll note that I've specified a font name and size for the barcode. I've used Arial 24pt but, if you substitute your barcode font's name and the required size, you should get the result you're after. I've also tweaked the 'Please refer to the above number on all correspondence' text & frame to suit.
Public Sub barcode()
Application.ScreenUpdating = False
Dim RngStory As Range, oFrm As Frame, sFrmTop As Single
For Each RngStory In ActiveDocument.StoryRanges
For Each oFrm In RngStory.Frames
With oFrm.Range.Find
.ClearFormatting
.Replacement.ClearFormatting
.Text = "Order Number: ([A-Z]{2})?([0-9]{7})"
.Replacement.Text = "*\1-\2*"
.Forward = True
.Wrap = wdFindStop
.Format = False
.MatchCase = False
.MatchWholeWord = False
.MatchWildcards = True
.MatchSoundsLike = False
.MatchAllWordForms = False
.Execute Replace:=wdReplaceOne
If .Found Then
With oFrm
.WidthRule = wdFrameAuto
.RelativeHorizontalPosition = wdRelativeHorizontalPositionMargin
.HorizontalPosition = InchesToPoints(3.75)
.HeightRule = wdFrameAuto
With .Range.Font
.Name = "Arial"
.Size = 24
.Bold = False
End With
sFrmTop = .VerticalPosition
End With
End If
.Text = "(Please refer to the) above( number )(on all correspondence.)"
.Replacement.Text = ChrW(&H25C4) & " \1^l" & ChrW(&H25C4) & " order\2^l" & ChrW(&H25C4) & " \3"
.Execute Replace:=wdReplaceOne
If .Found Then
With oFrm
.VerticalPosition = sFrmTop
.HeightRule = wdFrameAuto
.Width = InchesToPoints(1.4)
.RelativeHorizontalPosition = wdRelativeHorizontalPositionMargin
.HorizontalPosition = wdFrameRight
End With
End If
End With
Next oFrm
Next RngStory
Application.ScreenUpdating = True
End Sub
Powered by vBulletin® Version 4.2.5 Copyright © 2025 vBulletin Solutions Inc. All rights reserved.