Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3
Default Opening a Word document from Excel

I wish to put a commend button in an Excel spreadsheet which will open
an existing word document.

i.e D:/directory/document.doc

What code would I put behind the command button?

Any ideas?

Many thanks

PaddyMac
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,565
Default Opening a Word document from Excel

There might be a more elegant way, but this should work:

Dim MyDoc As Object
Set MyDoc = GetObject("D:/msword/directory/document.doc")
MyDoc.Application.Visible = True
MyDoc.Parent.Documents.Open FileName:="D:/msword/directory/document.doc"
MyDoc.Windows.Parent.Activate



"PaddyMac" wrote in message
...
I wish to put a commend button in an Excel spreadsheet which will open
an existing word document.

i.e D:/directory/document.doc

What code would I put behind the command button?

Any ideas?

Many thanks

PaddyMac



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,565
Default Opening a Word document from Excel

The last line did not belong with that snippet.

Dim MyDoc As Object
Set MyDoc = GetObject("D:/msword/directory/document.doc")
MyDoc.Application.Visible = True
MyDoc.Parent.Documents.Open FileName:="D:/msword/directory/document.doc"

"PaddyMac" wrote in message
...
I wish to put a commend button in an Excel spreadsheet which will open
an existing word document.

i.e D:/directory/document.doc

What code would I put behind the command button?

Any ideas?

Many thanks

PaddyMac



  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 15
Default Opening a Word document from Excel

JLGWhiz

Thanks for that - just about to try it out - please forgive the double
posting I repeated today - couldn't find my original and thought it hadn't
gone up.

Kindest

"JLGWhiz" wrote:

The last line did not belong with that snippet.

Dim MyDoc As Object
Set MyDoc = GetObject("D:/msword/directory/document.doc")
MyDoc.Application.Visible = True
MyDoc.Parent.Documents.Open FileName:="D:/msword/directory/document.doc"

"PaddyMac" wrote in message
...
I wish to put a commend button in an Excel spreadsheet which will open
an existing word document.

i.e D:/directory/document.doc

What code would I put behind the command button?

Any ideas?

Many thanks

PaddyMac




  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 15
Default Opening a Word document from Excel

JLGWhiz

It works perfectly!

Many, many thanks.

Kindest regards

PaddyMac

"JLGWhiz" wrote:

The last line did not belong with that snippet.

Dim MyDoc As Object
Set MyDoc = GetObject("D:/msword/directory/document.doc")
MyDoc.Application.Visible = True
MyDoc.Parent.Documents.Open FileName:="D:/msword/directory/document.doc"

"PaddyMac" wrote in message
...
I wish to put a commend button in an Excel spreadsheet which will open
an existing word document.

i.e D:/directory/document.doc

What code would I put behind the command button?

Any ideas?

Many thanks

PaddyMac






  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 15
Default Opening a Word document from Excel

JLGWhiz

What about the other way round? Opening an Excel Workbook from a command
button in a Word document.

Many thanks again for your help.

Kindest regards

PaddyMac

"JLGWhiz" wrote:

There might be a more elegant way, but this should work:

Dim MyDoc As Object
Set MyDoc = GetObject("D:/msword/directory/document.doc")
MyDoc.Application.Visible = True
MyDoc.Parent.Documents.Open FileName:="D:/msword/directory/document.doc"
MyDoc.Windows.Parent.Activate



"PaddyMac" wrote in message
...
I wish to put a commend button in an Excel spreadsheet which will open
an existing word document.

i.e D:/directory/document.doc

What code would I put behind the command button?

Any ideas?

Many thanks

PaddyMac




  #7   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,565
Default Opening a Word document from Excel

This is from the Word help file:

Dim MyXL As Object ' Variable to hold reference
' to Microsoft Excel.
Dim ExcelWasNotRunning As Boolean ' Flag for final release.

' Test to see if there is a copy of Microsoft Excel already running.
On Error Resume Next ' Defer error trapping.
' Getobject function called without the first argument returns a
' reference to an instance of the application. If the application isn't
' running, an error occurs.
Set MyXL = Getobject(, "Excel.Application")
If Err.Number < 0 Then ExcelWasNotRunning = True
Err.Clear ' Clear Err object in case error occurred.

' Check for Microsoft Excel. If Microsoft Excel is running,
' enter it into the Running Object table.
DetectExcel

' Set the object variable to reference the file you want to see.
Set MyXL = Getobject("c:\vb4\MYTEST.XLS")

' Show Microsoft Excel through its Application property. Then
' show the actual window containing the file using the Windows
' collection of the MyXL object reference.
MyXL.Application.Visible = True
MyXL.Parent.Windows(1).Visible = True
Do manipulations of your file here.




"PaddyMac" wrote in message
...
JLGWhiz

What about the other way round? Opening an Excel Workbook from a command
button in a Word document.

Many thanks again for your help.

Kindest regards

PaddyMac

"JLGWhiz" wrote:

There might be a more elegant way, but this should work:

Dim MyDoc As Object
Set MyDoc = GetObject("D:/msword/directory/document.doc")
MyDoc.Application.Visible = True
MyDoc.Parent.Documents.Open
FileName:="D:/msword/directory/document.doc"
MyDoc.Windows.Parent.Activate



"PaddyMac" wrote in message
...
I wish to put a commend button in an Excel spreadsheet which will open
an existing word document.

i.e D:/directory/document.doc

What code would I put behind the command button?

Any ideas?

Many thanks

PaddyMac






  #8   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 15
Default Opening a Word document from Excel

JLGWhiz

Once again, it works!

Thanks again.

Kindest regards

PaddyMac

"PaddyMac" wrote:

JLGWhiz

It works perfectly!

Many, many thanks.

Kindest regards

PaddyMac

"JLGWhiz" wrote:

The last line did not belong with that snippet.

Dim MyDoc As Object
Set MyDoc = GetObject("D:/msword/directory/document.doc")
MyDoc.Application.Visible = True
MyDoc.Parent.Documents.Open FileName:="D:/msword/directory/document.doc"

"PaddyMac" wrote in message
...
I wish to put a commend button in an Excel spreadsheet which will open
an existing word document.

i.e D:/directory/document.doc

What code would I put behind the command button?

Any ideas?

Many thanks

PaddyMac




  #9   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 15
Default Opening a Word document from Excel

JLGWhiz

How would I alter this code to open an Access Database?

I assume all the code would be the same except what would go in the place of
"MyDoc"?

Many thanks

Kindest regards

PaddyMac

"PaddyMac" wrote:

JLGWhiz

It works perfectly!

Many, many thanks.

Kindest regards

PaddyMac

"JLGWhiz" wrote:

The last line did not belong with that snippet.

Dim MyDoc As Object
Set MyDoc = GetObject("D:/msword/directory/document.doc")
MyDoc.Application.Visible = True
MyDoc.Parent.Documents.Open FileName:="D:/msword/directory/document.doc"

"PaddyMac" wrote in message
...
I wish to put a commend button in an Excel spreadsheet which will open
an existing word document.

i.e D:/directory/document.doc

What code would I put behind the command button?

Any ideas?

Many thanks

PaddyMac




  #10   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 15
Default Opening a Word document from Excel

JLGWhiz

Many thanks again - it seemed to run last week but I tried it in a different
Word document and it is jamming at the DetectExcel command.

with

COMPILE ERROR

SUB OR FUNCTION NOT DEFINED.

Any ideas

Kind regards

PaddyMac

Private Sub CommandButton2_Click()

Dim MyXL As Object ' Variable to hold reference
' to Microsoft Excel.
Dim ExcelWasNotRunning As Boolean ' Flag for final release.

' Test to see if there is a copy of Microsoft Excel already running.
On Error Resume Next ' Defer error trapping.
' Getobject function called without the first argument returns a
' reference to an instance of the application. If the application isn't
' running, an error occurs.
Set MyXL = GetObject(, "Excel.Application")
If Err.Number < 0 Then ExcelWasNotRunning = True
Err.Clear ' Clear Err object in case error occurred.

' Check for Microsoft Excel. If Microsoft Excel is running,
' enter it into the Running Object table.
DetectExcel

' Set the object variable to reference the file you want to see.
Set MyXL = GetObject("J:\P-10\NAPLAN_2009\Data Management\Results\Helpdesk
Old Pass.XLS")

' Show Microsoft Excel through its Application property. Then
' show the actual window containing the file using the Windows
' collection of the MyXL object reference.
MyXL.Application.Visible = True
MyXL.Parent.Windows(1).Visible = True
' Do manipulations of your file here.



End Sub

"JLGWhiz" wrote:

This is from the Word help file:

Dim MyXL As Object ' Variable to hold reference
' to Microsoft Excel.
Dim ExcelWasNotRunning As Boolean ' Flag for final release.

' Test to see if there is a copy of Microsoft Excel already running.
On Error Resume Next ' Defer error trapping.
' Getobject function called without the first argument returns a
' reference to an instance of the application. If the application isn't
' running, an error occurs.
Set MyXL = Getobject(, "Excel.Application")
If Err.Number < 0 Then ExcelWasNotRunning = True
Err.Clear ' Clear Err object in case error occurred.

' Check for Microsoft Excel. If Microsoft Excel is running,
' enter it into the Running Object table.
DetectExcel

' Set the object variable to reference the file you want to see.
Set MyXL = Getobject("c:\vb4\MYTEST.XLS")

' Show Microsoft Excel through its Application property. Then
' show the actual window containing the file using the Windows
' collection of the MyXL object reference.
MyXL.Application.Visible = True
MyXL.Parent.Windows(1).Visible = True
Do manipulations of your file here.




"PaddyMac" wrote in message
...
JLGWhiz

What about the other way round? Opening an Excel Workbook from a command
button in a Word document.

Many thanks again for your help.

Kindest regards

PaddyMac

"JLGWhiz" wrote:

There might be a more elegant way, but this should work:

Dim MyDoc As Object
Set MyDoc = GetObject("D:/msword/directory/document.doc")
MyDoc.Application.Visible = True
MyDoc.Parent.Documents.Open
FileName:="D:/msword/directory/document.doc"
MyDoc.Windows.Parent.Activate



"PaddyMac" wrote in message
...
I wish to put a commend button in an Excel spreadsheet which will open
an existing word document.

i.e D:/directory/document.doc

What code would I put behind the command button?

Any ideas?

Many thanks

PaddyMac






Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Opening word document through excel vba srinums Excel Discussion (Misc queries) 0 June 8th 06 12:02 PM
Opening a Word and/or PDF document from Excel Vikesh Jain Excel Programming 1 November 29th 05 11:51 AM
Opening Word Document with excel [email protected] Excel Discussion (Misc queries) 0 March 21st 05 01:49 AM
opening a word document from excel chris Excel Programming 5 April 1st 04 03:17 PM
Opening a Word Document in Excel Tonja Excel Programming 2 September 18th 03 02:56 AM


All times are GMT +1. The time now is 07:26 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"