Loading
Word.Tips.Net WordTips (Menu Interface)

Processing Information Pasted from a PDF File

Please Note: This article is written for users of the following Microsoft Word versions: 97, 2000, 2002, and 2003. If you are using a later version (Word 2007 or later), this tip may not work for you. For a version of this tip written specifically for later versions of Word, click here: Processing Information Pasted from a PDF File.

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.

WordTips is your source for cost-effective Microsoft Word training. (Microsoft Word is the most popular word processing software in the world.) This tip (583) applies to Microsoft Word 97, 2000, 2002, and 2003. You can find a version of this tip for the ribbon interface of Word (Word 2007 and later) here: Processing Information Pasted from a PDF File.

Related Tips:

The First and Last Word on Word! Bestselling For Dummies author Dan Gookin puts his usual fun and friendly candor back to work to show you how to navigate Word 2013. Spend more time working and less time trying to figure it all out! Check out Word 2013 For Dummies today!

 

Leave your own comment:

*Name:
Email:
  Notify me about new comments ONLY FOR THIS TIP
Notify me about new comments ANYWHERE ON THIS SITE
Hide my email address
*Text:
*What is 5+3 (To prevent automated submissions and spam.)
 
 
           Commenting Terms

Comments for this tip:

Eddy    11 Aug 2012, 16:06
Fixed it by the following. View/Macros; select the macro to edit; Tools/References/Browse; select FM20.DLL open.

A better CRLF eliminator is at http://sourceforge.net/projects/wordwrap-macro/, but change macro name from "X-XS-CRLFs" to "XXSCRLFs".
This macro only deletes CRLF on what is selected.
Eddy    11 Aug 2012, 15:23
Same problem as Carol.
"Compiler error: User-defined type not defined" at "Dim MyData As DataObject"
It does not like DataObject.
Carol L. Kelley    19 Jul 2012, 16:59
I ran the macro and am coming back with complile error: User-defined type not defined. Any suggestions?
 
 

Our Company

Sharon Parq Associates, Inc.

About Tips.Net

Contact Us

 

Advertise with Us

Our Privacy Policy

Our Sites

Tips.Net

Beauty and Style

Cars

Cleaning

Cooking

DriveTips (Google Drive)

ExcelTips (Excel 97–2003)

ExcelTips (Excel 2007–2016)

Gardening

Health

Home Improvement

Money and Finances

Organizing

Pests and Bugs

Pets and Animals

WindowsTips (Microsoft Windows)

WordTips (Word 97–2003)

WordTips (Word 2007–2016)

Our Products

Helpful E-books

Newsletter Archives

 

Excel Products

Word Products

Our Authors

Author Index

Write for Tips.Net

Copyright © 2016 Sharon Parq Associates, Inc.