opening an excel document in word

Z

zoot

Hello All

Does anyone know if it is possible to open an excel document from word? I
am trying to copy information from a word document to excel but cannot
figure out how to open the excel document from word.

Thanks in advance
 
A

Anne Troy

You seem to be contradicting yourself. First you say "Open Excel file from
Word" and then you say "Copy information from Word to Excel". Which is it?
:)
Yes, you can open an Excel file from Word, but you're likely to get a couple
of warnings while you do it. Just File-->Open and change the Files of type
at the bottom to All Files, and choose the Excel file. Make sure you save it
as a DOC so you don't overwrite your original Excel file. For some more
references that may help you:
http://www.officearticles.com/word/excel_contents_in_microsoft_word.htm

*******************
~Anne Troy

www.OfficeArticles.com
 
Z

zoot

Your right that made no sense - what i am trying to do is open an excel
document from a macro.
 
D

Dave Peterson

This worked ok for me from MSWord.

Option Explicit
Sub testme01()

Dim XLApp As Object
Dim XLWkbk As Object
Dim xlWks As Object
Dim testStr As String

Dim XLWasRunning As Boolean
Dim myFileName As String

myFileName = "C:\my documents\excel\book1.xls"

testStr = ""
On Error Resume Next
testStr = Dir(myFileName)
On Error GoTo 0

If testStr = "" Then
MsgBox myFileName & " wasn't found"
Exit Sub
End If

XLWasRunning = True
On Error Resume Next
Set XLApp = GetObject(, "Excel.Application")
If Err.Number <> 0 Then
Set XLApp = CreateObject("Excel.Application")
XLWasRunning = False
End If
On Error GoTo 0

XLApp.Visible = True 'Nice for testing

Set XLWkbk = XLApp.workbooks.Open(FileName:=myFileName)
Set xlWks = Nothing
On Error Resume Next
Set xlWks = XLWkbk.worksheets("sheet1")
On Error GoTo 0

If xlWks Is Nothing Then
MsgBox "That sheet doesn't exist"
Else
xlWks.Range("a1").Value = "hi there"
End If

XLWkbk.Close savechanges:=True
If XLWasRunning Then
'do nothing
Else
XLApp.Quit
End If

Set xlWks = Nothing
Set XLWkbk = Nothing
Set XLApp = Nothing

End Sub
 

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