#1
|
|||
|
|||
Insert Range from Excel File into Word
My apologies if this has been addressed elsewhere. I've been trying in both Word 2010 and Word 2013 to Insert > Text from file and choosing a named range in an Excel file. However, each time I try this I get the following message:
The file xxx cannot be opened because there are problems with the contents.This occurs even when I create a brand new Excel file and save it. Am I doing something incorrectly or is there a different way to do what I want other than copying from Excel and pasting into Word? Thanks in advance! |
#2
|
||||
|
||||
You cannot insert Excel ranges like this, only Word ranges. You can do it with a Word macro/ The following will paste the named range from the named file at the cursor:
Code:
Sub InsertExcelRange() 'Graham Mayor - https://www.gmayor.com - Last updated - 15 Jul 2019 Dim xlApp As Object Dim xlWb As Object Dim strWB As String Dim bStarted As Boolean, bOpened As Boolean Const strWorkbook As String = "workbook path" Const xlRange As String = "excel range name" On Error Resume Next Set xlApp = GetObject(, "Excel.Application") If Err <> 0 Then Set xlApp = CreateObject("Excel.Application") bStarted = True End If On Error GoTo 0 'Open the workbook to input the data strWB = Dir(strWorkbook) On Error Resume Next Set xlWb = xlApp.Workbooks(strWB) If xlWb Is Nothing Then Set xlWb = xlApp.Workbooks.Open(strWorkbook) bOpened = True End If On Error GoTo 0 xlApp.GoTo Reference:="Pension" xlApp.Selection.Copy Selection.Paste If bOpened Then xlWb.Close 0 If bStarted Then xlApp.Quit lbl_Exit: Set xlApp = Nothing Set xlWb = Nothing Exit Sub End Sub
__________________
Graham Mayor - MS MVP (Word) (2002-2019) Visit my web site for more programming tips and ready made processes www.gmayor.com |
#3
|
|||
|
|||
Thank you!!
|
Tags |
excel range, insert text from file |
|
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
Insert image into powerpoint from cell in Excel file | JJERINC | PowerPoint | 0 | 11-16-2018 09:05 AM |
Set Excel Range using Word | gbrew584 | Word VBA | 3 | 12-07-2015 01:51 PM |
OFFICE(Word,Excel..)-crash/close when DIALOG BOX launched of insert image,open file | buggingme | Office | 1 | 05-30-2010 12:18 AM |
Through VBA, export range from Excel to Word | duugg | Word VBA | 0 | 08-24-2009 07:50 PM |
Trying to insert hyperlink to excel file into Outlook | KarenE | Outlook | 0 | 05-08-2006 12:56 PM |