Word linking to excel

C

Cresta

Hello and help
Word 2007, I need to copy a named range from a closed Excel file, then paste
special it as a Paste Link - Microsoft Office Excel Worksheet Object in to
the active Word document.

So far I have the following code which copies the whole Excel sheet ,

Dim FileName As String
FileName = "c:\\Test.688.xls"
FileName = "LINK Excel.Sheet.12 """ & FileName & """ \a "
Selection.TypeText FileName
Selection.Fields.Add Range:=Selection.Range, Type:=wdFieldEmpty, Text:= _
FileName, _
PreserveFormatting:=True


But I need to restrict this to a named range.
Any ideas or pointers

Thanks
 
J

Jean-Guy Marcil

Cresta was telling us:
Cresta nous racontait que :
Hello and help
Word 2007, I need to copy a named range from a closed Excel file,
then paste special it as a Paste Link - Microsoft Office Excel
Worksheet Object in to the active Word document.

So far I have the following code which copies the whole Excel sheet ,

Dim FileName As String
FileName = "c:\\Test.688.xls"
FileName = "LINK Excel.Sheet.12 """ & FileName & """ \a "
Selection.TypeText FileName
Selection.Fields.Add Range:=Selection.Range, Type:=wdFieldEmpty,
Text:= _ FileName, _
PreserveFormatting:=True


But I need to restrict this to a named range.
Any ideas or pointers

Thanks

Add a statement under
FileName = "c:\\Test.688.xls"
for the named range:
SheetName = "SheetName!NamedRangeName"

Then change the second FileName statement from
FileName = "LINK Excel.Sheet.12 """ & FileName & """ \a "
to
FileName = "LINK Excel.Sheet.12 """ & FileName & """ """ & SheetName &
""" \a "

By the way, why do you use
Selection.TypeText FileName
?
Do you need to see the field code in the document, but outside the field
istelf?

--

Salut!
_______________________________________
Jean-Guy Marcil - Word MVP
(e-mail address removed)
Word MVP site: http://www.word.mvps.org
 
C

Cresta

Thanks for you help, that works fine.
Jean-Guy Marcil said:
Cresta was telling us:
Cresta nous racontait que :


Add a statement under
FileName = "c:\\Test.688.xls"
for the named range:
SheetName = "SheetName!NamedRangeName"

Then change the second FileName statement from
FileName = "LINK Excel.Sheet.12 """ & FileName & """ \a "
to
FileName = "LINK Excel.Sheet.12 """ & FileName & """ """ & SheetName &
""" \a "

By the way, why do you use
Selection.TypeText FileName
?
Do you need to see the field code in the document, but outside the field
istelf?

--

Salut!
_______________________________________
Jean-Guy Marcil - Word MVP
(e-mail address removed)
Word MVP site: http://www.word.mvps.org
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top