macro to open a document

T

Todd

How do I write a macro to open a document? I tried to record a macro and go
this macro that selects a cell and follows a hyperlink. But I would like to
put the address of the doc. into the macro and not have the hyperlink in a
cell on the document.

Sub OpenTemplate()
Range("AH1").Select
Selection.Hyperlinks(1).Follow NewWindow:=False, AddHistory:=True
ActiveWindow.ActivateNext
End Sub


Thanks,


Todd
 
P

Penny Miller

Read the responses to Michelle Hanan's Opening doc in macro that was posted
on 7/12
 
T

Todd

Ok, Thanks.

From that I have this statement below. I am getting "a user defined type
not defined error with the dim statement". I am looking at the library for
excel types and don't know which one to choose?

Thanks.

Sub opendoc()
Dim MyDoc As Excel.xls
'Set MyDoc = Excel.Documents.Open("C:\MyFiles\MyDoc.xls")
End Sub
 
P

Penny Miller

Try this;

Dim appWord As Object
Dim myDoc As Object
Set appWord = CreateObject("Word.Application")
Set myDoc = appWord.Documents.Open("C:\MyFiles\MyDoc.xls")
 
T

Todd

Thanks! This is closer. I am sorry that I don't know more and can just fix
it. This opens a my excel file as a word doc. How do I get it to open it in
excel? I tried replacing the text "word" with "excel" but as I am sure you
know, it didn't work.


Thanks again,

Todd
 
P

Penny Miller

I guess I must have misunderstood you, I thought you needed to open a
document not a workbook. Instead try this code;

Sub OpenWorksheet()
'
' Opens Worksheet Macro
' Macro recorded 8/3/2006
'
Workbooks.Open Filename:="C:\MyFiles\MyWorksheet.xls"
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