Paste from word

odsmith

Board Regular
Joined
Nov 15, 2012
Messages
68
Let’s say you get an email formatted in MS Word. The list has some names that are highlighted and some are not. Action is required on highlighted items.


Now, you want to manipulate the text based on the highlighted text. However, if you paste the data in excel as text only, the highlighted portions do not come into excel. But, if you paste as a picture, metafile, link, ect, you can’t edit the text.


Are there any ways to manipulate the object?
 

Excel Facts

Can you sort left to right?
To sort left-to-right, use the Sort dialog box. Click Options. Choose "Sort left to right"
Not sure if this is what your looking for, but If you just want the data that is highlighted in your spreadsheet you can copy it like this and then Paste it using the below method.

CLICK HERE FOR EXAMPLE
 
Upvote 0
Hmmm not too sure how to go about this using the Word Object library. I would guess that you would need to do something like this:

1. Cycle through each individual word in the MS Word document. If the word is highlighted then add an additional character to it, like a "@" or something of the sort.
2. Copy and paste data into MS Excel.
3. Do manipulation on action items based on "@" symbol.
4. Clear the additional character using Find and Replace.

I am not sure how to accomplish this, but maybe someone else will be able to assist you.
 
Upvote 0
Have you tried, Paste instead of Paste Special? Normally that works. You can also try Paste Special as HTML, for your convenience.
 
Upvote 0
Yes, that pastes just the text only.

I have come up with the below code to accomplish what I needed.

Thanks All


Code:
Public Sub ParseDoc()

Dim doc As Document
Set doc = ActiveDocument
Dim paras As Paragraphs
Set paras = doc.Paragraphs
Dim para As Paragraph
Dim sents As Sentences
Dim sent As Range
For Each para In paras

    Set sents = para.Range.Sentences
    For Each sent In sents
        dot = 0
        dot = InStr(1, Trim(sent.Text), ".")
        high = sent.HighlightColorIndex
        test = 0
        If dot > 0 Or high > 0 Then
            test = 1
        End If
        
        If test = 0 Then sent.Delete
    Next

Next

End Sub
 
Upvote 0
Thanks for posting the solution. This is interesting. I'm going to store it away in case I ever need to manipulate a MS Word Document in this manner.
 
Upvote 0

Forum statistics

Threads
1,222,437
Messages
6,166,026
Members
452,008
Latest member
Customlogoflipflops

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top