?
Solved

Need to use VBA to do what <CTRL>-<F9> does from the keyboard in word.

Posted on 2005-03-29
1
Medium Priority
?
755 Views
Last Modified: 2008-02-01
I want to insert one specific cell from an excel spreadsheet into word.

I currently do this by pressing <ctrl<-<f9> while in word and then typing:
LINK Excel.Sheet.8 "\\\\server\\path\\to\\excel\\file\\filename.xls" "Cell_Name" \a \t  
in the field.

How can I do this from VBA in Excel or Ms Access?

Thanks a bunch!
0
Comment
Question by:jasgot
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
1 Comment
 
LVL 11

Accepted Solution

by:
Steiner earned 1000 total points
ID: 13659284
Try this one, be sure so set a reference to the Word object library inside the application this code should run:

Option Explicit

Sub WdField()
   Dim WdApp As Word.Application, WdDoc As Word.Document, rng As Word.Range
   
   Set WdApp = New Word.Application
   
   'The document to insert the field into
   Set WdDoc = WdApp.Documents.Open("e:\test\fields.doc")
   
   'The bookmark that marks the position, called bm_field
   rng = WdDoc.Bookmarks("bm_field").Select
   
   WdDoc.Fields.Add rng, wdFieldLink, "Excel.Sheet.8 ""\\\\server\\path\\to\\excel\\file\\filename.xls"" ""Cell_Name"" \a \t"
   WdDoc.Save
   WdDoc.Close
   Set WdDoc = Nothing
   
   WdApp.Quit
   Set WdApp = Nothing
End Sub
0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Do you ever need to create a 20 page Word document for some testing purpose? Are you tired of copying & pasting old boring "lorem ipsum" text over and over again, increasing font size and line space in order to make the document 20+ pages long? Look…
This article shows how to get a list of available printers for display in a drop-down list, and then to use the selected printer to print an Access report or a Word document filled with Access data, using different syntax as needed for working with …
Learn how to make your own table of contents in Microsoft Word using paragraph styles and the automatic table of contents tool. We'll be using the paragraph styles in Word’s Home toolbar to help you create a table of contents. Type out your initial …
In a previous video Micro Tutorial here at Experts Exchange (http://www.experts-exchange.com/videos/1358/How-to-get-a-free-trial-of-Office-365-with-the-Office-2016-desktop-applications.html), I explained how to get a free, one-month trial of Office …
Suggested Courses

801 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question