Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
DiscussionsAccessExcelInfoPathOutlookPowerPointPublisherWord
DirectoryUser Groups
Related Topics
Outlook ExpressInternet ExplorerWindowsMS Server ProductsMore Topics ...

MS Office Forum / Word / Programming / October 2007

Tip: Looking for answers? Try searching our database.

Word linking to excel

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Cresta - 05 Oct 2007 14:37 GMT
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
Cresta - 05 Oct 2007 15:01 GMT
Found it, anyone interested here is the code

> Dim FileName As String
> FileName ="c:\\ExcelFile.xls" & """ """ & "Sheet1!NamedRange"""
[quoted text clipped - 3 lines]
>         FileName, _
>         PreserveFormatting:=True

> Hello and help
> Word 2007, I need to copy a named range from a closed Excel file, then paste
[quoted text clipped - 15 lines]
>
> Thanks
Jean-Guy Marcil - 05 Oct 2007 15:32 GMT
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,
[quoted text clipped - 15 lines]
>
> 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?

Signature

Salut!
_______________________________________
Jean-Guy Marcil - Word MVP
jmarcilREMOVE@CAPSsympatico.caTHISTOO
Word MVP site: http://www.word.mvps.org

Cresta - 05 Oct 2007 15:50 GMT
Thanks for you help, that works fine.

> Cresta was telling us:
> Cresta nous racontait que :
[quoted text clipped - 35 lines]
> Do you need to see the field code in the document, but outside the field
> istelf?

Rate this thread:






 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.