+ Reply to Thread
Results 1 to 3 of 3

Copying into excel range from word range with formatting

Hybrid View

  1. #1
    Registered User
    Join Date
    03-06-2008
    Posts
    3

    Copying into excel range from word range with formatting

    I am tring to copy some text from a word application to an excel cell. The text is to be copied from a Word.Range (wrng) object to an excel range object (erng) [Is there some better way to do this task than range to range copy?]. The text has some formatting also. For example its like “This is a sample text with bold character in it”. In this text the word ‘bold’ is actually bold. When I do
    wrng.Copy() and then erng.PasteSpecial(..). It is not working as desired. I want the formatting information to be preserved after paste in the excel cell but its getting copied without formatting. the character ‘bold’ is not bold after the paste.

    I am using Paste option of xlPasteAll (in which case the text is getting paste as a picture. When I use xlPasteFormat/xlPasteValue etc, txt gets paste without formatting info.

    Can any body help as to how to achieve this task?

    Thanks for your help in advance.
    Sourav

  2. #2
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,259
    Hello souravsain,

    Here is a sample macro that copies the first paragraph of of the open Word document into "Sheet1 $A$3". You will need to make some name changes to match your code.
    Sub CopyWordToExcel()
    
      Dim wdApp As Object
      Dim wdDoc As Object
      
       'Use the Word document that is already open.
        Set wdApp = GetObject(, "Word.application")
        Set wdDoc = wdApp.ActiveDocument
        
         'Copy the first paragraph
          wdDoc.Paragraphs(1).Range.Copy
        
         'Paste it into cell "A3" on "Sheet1"
          Worksheets("Sheet1").Paste Destination:=Range("A3")
      
    End Sub
    Sincerely,
    Leith Ross

  3. #3
    Registered User
    Join Date
    03-06-2008
    Posts
    3

    Thanks a lot!

    Thanks a lot Leith.
    This helped.

    Regards,
    Sourav

    Quote Originally Posted by Leith Ross
    Hello souravsain,

    Here is a sample macro that copies the first paragraph of of the open Word document into "Sheet1 $A$3". You will need to make some name changes to match your code.
    Sub CopyWordToExcel()
    
      Dim wdApp As Object
      Dim wdDoc As Object
      
       'Use the Word document that is already open.
        Set wdApp = GetObject(, "Word.application")
        Set wdDoc = wdApp.ActiveDocument
        
         'Copy the first paragraph
          wdDoc.Paragraphs(1).Range.Copy
        
         'Paste it into cell "A3" on "Sheet1"
          Worksheets("Sheet1").Paste Destination:=Range("A3")
      
    End Sub
    Sincerely,
    Leith Ross

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1