Copy / Paste from Excel to Word

Dziblock

New Member
Joined
Aug 27, 2019
Messages
4
Hi,


Is it possible to extract data from a cell in Excel and paste it in a specific place, for example, the second table of a Word template, row 2, cell 3?
So far, I've only managed to paste the data at the end of the Word doc...


Thanks
wink.gif
 

Excel Facts

Last used cell?
Press Ctrl+End to move to what Excel thinks is the last used cell.
Hi @★ Dziblock, welcolme to the forum.

You can do the following, in your Word template, on the site where you want to paste the excel range, type a specific text.
For example:

7bb346f92f7f43e03a52dde62cc9e220.jpg


--------------------------------------------------------------------------------
With the following code you can copy a range of cells and paste in the word:


Code:
Sub Excel_To_Word()
  Application.ScreenUpdating = False
  Dim h1 As Worksheet, wPath As String, wTemplate As String, wText As String
  Dim objWord As Object
  '
  Set h1 = Sheets("[COLOR=#ff0000]Sheet5[/COLOR]")
  wPath = "[COLOR=#ff0000]C:\trabajo\books\[/COLOR]"
  wTemplate = "[COLOR=#ff0000]MyTemplate.dotx[/COLOR]"
  wText = "[COLOR=#ff0000]Here_Paste_Range[/COLOR]"
  '
  Set objWord = CreateObject("Word.Application")
  objWord.Visible = True
  objWord.Documents.Add template:=wPath & wTemplate, NewTemplate:=False, DocumentType:=0
  '
  h1.Range("[COLOR=#ff0000]A1:D10[/COLOR]").Copy
  objWord.Selection.Move 6, -1 'moverse al principio del documento
  objWord.Selection.Find.Execute FindText:=wText
  If objWord.Selection.Find.found = True Then
    objWord.Selection.PasteExcelTable False, True, False
  End If
  objWord.Activate
  objWord.ActiveDocument.SaveAs wPath & "[COLOR=#ff0000]NewWord[/COLOR]"
  objWord.ActiveDocument.Close
  objWord.Quit
  '
  Application.CutCopyMode = False
End Sub

Change the data in red for your information.
 
Upvote 0
Thanks Dante, your solution seems ok and I may use it for another problem but for the Word table, I've received this solution from another forum and it works perfectly:

Code:
ActiveDocument.Tables(2).Cell(2, 3).Range = Range("A1")
 
Upvote 0
@Dziblock
For future reference
While we do not prohibit Cross-Posting on this site, we do ask that you please mention you are doing so and provide links in each of the threads pointing to the other thread (see rule 13 here along with the explanation: Forum Rules).
This way, other members can see what has already been done in regards to a question, and do not waste time working on a question that may already be answered.

https://www.msofficeforums.com/excel-programming/43287-export-data-word-table.html
 
Upvote 0

Forum statistics

Threads
1,214,376
Messages
6,119,180
Members
448,871
Latest member
hengshankouniuniu

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