none
Export from Excel to Word using vba RRS feed

  • Question

  • Hi,

    I used

    Cells(i, j).Copy
              
    appWD.Selection.PasteSpecial Placement:=wdInLine, DataType:=wdPasteText

    inside two for-loop to copy a particular cell and paste the cell in word document.

    two problem:

    1. The appWD command paste the cell in the word, but I want the content of the cell to be pasted with plain text?

    2. Sometimes the vba complain about the clipboard object?

    David

    Wednesday, September 10, 2014 10:36 AM

Answers

  • If Not IsEmpty(cell) Then

    Wednesday, September 10, 2014 2:41 PM
  • In VBE click Tools -> References and add references to Microsoft Word 14.0 Object Library and then 

    Sub Main()
    
        Dim wb As Workbook
        Set wb = ThisWorkbook
        
        Cells(1, 1).Copy
    
        Dim wd As New Word.Application
        wd.Application.Visible = True
        
        Dim wdDoc As Word.Document
        Set wdDoc = wd.Documents.Add
        
        wdDoc.Paragraphs(1).Range.PasteSpecial Placement:=wdInLine, DataType:=wdPasteText
        
    End Sub

    This macro will open Word and paste the text from cell to word as text.

    Wednesday, September 10, 2014 11:00 AM

All replies

  • In VBE click Tools -> References and add references to Microsoft Word 14.0 Object Library and then 

    Sub Main()
    
        Dim wb As Workbook
        Set wb = ThisWorkbook
        
        Cells(1, 1).Copy
    
        Dim wd As New Word.Application
        wd.Application.Visible = True
        
        Dim wdDoc As Word.Document
        Set wdDoc = wd.Documents.Add
        
        wdDoc.Paragraphs(1).Range.PasteSpecial Placement:=wdInLine, DataType:=wdPasteText
        
    End Sub

    This macro will open Word and paste the text from cell to word as text.

    Wednesday, September 10, 2014 11:00 AM
  • Thanks it worked.

    Yet another question, how to handle the blank cells in excel when paste special reaches them?

    Wednesday, September 10, 2014 1:08 PM
  • If Not IsEmpty(cell) Then

    Wednesday, September 10, 2014 2:41 PM