Welcome toWord.Tips.Net
Ask a Word Question
Make a Comment
Learn Access Now
Free Printable Forms
Beauty Tips
Car Tips
Cleaning Tips
College Tips
Cooking Tips
Excel2007 Tips
ExcelTips
Family Tips
Gardening Tips
Health Tips
Home Tips
Legal Tips
Money Tips
Organizing Tips
Pest Tips
Pet Tips
Wedding Tips
Word2007 Tips
WordTips
Setting Fraction Bar Overhang Spacing in the Equation Editor
Printing On Both Sides of the Paper
Turning Off AutoComplete for Dates
Understanding Auto Line Spacing
Adding Comments to Your Document
Conditional Calculations in Word
Zach is constantly pasting quotes from PDF files into the body of his Word documents. He'd like to have a macro specifically for pasting from PDF that pastes without any formatting and automatically removes the paragraph breaks that are at the end of each line of the pasted text.
It is relatively easy to work with text in this manner in a macro. All you need to do is move the information from the Clipboard to a string variable. Once it is in the variable, there is no longer any formatting associated with the text and you can search for and replace the paragraph breaks. The following macro performs both steps:
Sub PastePDFClean()
Dim MyData As DataObject
Dim sTextIn As String
Dim x As Integer
Dim y As Integer
Set MyData = New DataObject
MyData.GetFromClipboard
sTextIn = MyData.GetText
x = InStr(sTextIn, vbCr)
y = 1
While x > 0
sTextIn = Left(sTextIn, x - 1) & Mid(sTextIn, x + 1)
y = x + 1
x = InStr(y, sTextIn, vbCr)
Wend
Selection.TypeText sTextIn
Set MyData = Nothing
End Sub
Remember; the macro works on whatever is in the Clipboard. So, in order to run the macro properly on a PDF selection, you need to copy the selection to the Clipboard and switch to your Word document before you run the macro.
Tip #583 applies to Microsoft Word versions: 97 2000 2002 2003 2007
More Power! For some people, the prospect of creating Word macros can be scary. WordTips: The Macros can help you conquer your fears and you'll discover you're much more confident and productive as you make Word do exactly what you want. This is an invaluable source for learning macros. You are introduced to the topic in bite-sized chunks, pulled from past issues of WordTips. Learn at your own pace, exactly the way you want.