Excel cell reference in Word Macro

E

ekreider

I have an Excel Spreadsheet that contains some information and I'am try to
reference to one cell in the Excel workbook. This cell needs to be entered
into a New Word document Macro so I can go to our Company Intranet and open
the word document that contains the information I need. The information
needed form our Intranet is to be copied and entered into a New Word documeny
that is to be printed.

Example of code.

e = Excel cell
of = "http//www.psc.uss.com/documents/ECP/02/01/" & e & ".doc"
Documents. Open FileName:=of

The above works when I put the Excel cell information in the Macro. I can
then copy all the information needed and the rest of the Macro runs fine.

I am new at writting code for Word, but do a good job of Excel code.

Please help.

Thanks,

ekreider
 
T

Tony Jollans

I'm not sure what your question is.

To pick up data from a workbook you need to open it first, something like ..

Set xl = CreateObject("Excel.Application")
xl.Workbooks.Open("D:\Path\To\Book.xls")
Cel = xl.Range("Sheet1!A1") ' or whatever
xl.Quit
Set xl = Nothing
 
E

ekreider

Tony,

I want to thank you for you responce. The information that you gave me was
helpful somewhat, but I keep getting an error when I get to the part of the
code

Cel = xl.Range("Information Sheet!F3")

The error code is "Application-defined or object-defined error"

I am using Word 2000 if that helps any.
The Excel Workbok is opened and remains open before the Word documents are
opened, because the Excel workbook must do some calculations to detrimn which
word document to open.

Thanks again for your help.

Thanks,

ekreider
 
T

Tony Jollans

I ... do a good job of Excel code

You will know, then, that when the Sheet Name has a space in it, it must be
enclosed in quotes.

Cel = xl.Range("'Information Sheet'!F3")
 
E

ekreider

Tony,

I still get the same error.

Thank you so much for your help

Thanks,

ekreider
 
T

Tony Jollans

I'm sorry, I didn't read all the way to the end of your post. If you have
Excel already open with your workbook then you would be better doing

Set xl = GetObject(,"Excel.Application")

and then using normal excel commands (prefixed with xl.) to move around and
work with the workbooks and data. When you're done you probably do *not*
want the xl.quit line.
 
E

ekreider

Tony,

That worked PERFECTLY.

Thank you again and again for your hard work.

Thanks

ekreider
 

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