Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Anthony
 
Posts: n/a
Default Printing MS Word Doc From MS Excel

Hi,
I have a workbook in Excel where I want to be able to
place a button that will print a letter that has been
created in a seperate MS Word documnet.
I have tried recording a macro but nothing happened.

Is there a way to link the two together to enable
this 'button' to produce the letter ??

Thanks

Anthony
  #2   Report Post  
Dave Peterson
 
Posts: n/a
Default

I put a commandbutton from the Control Toolbox toolbar on a worksheet.

This is the code I used (double click on that commandbutton and paste this
code):

Option Explicit
Private Sub CommandButton1_Click()

'Dim WDApp As Word.Application
'Dim WDDoc As Word.Document
Dim WDApp As Object
Dim WDDoc As Object
Dim myDocName As String
Dim WordWasRunning As Boolean
Dim testStr As String

myDocName = "C:\my documents\word\document1.doc"

testStr = ""
On Error Resume Next
testStr = Dir(myDocName)
On Error GoTo 0
If testStr = "" Then
MsgBox "Word file not found!"
Exit Sub
End If

WordWasRunning = True
On Error Resume Next
Set WDApp = GetObject(, "Word.Application")
If Err.Number < 0 Then
Set WDApp = CreateObject("Word.Application")
WordWasRunning = False
End If

WDApp.Visible = True 'at least for testing!

Set WDDoc = WDApp.documents.Open(Filename:=myDocName)
WDDoc.PrintOut '.printPreview while testing???
WDDoc.Close savechanges:=False

If WordWasRunning Then
'leave it running
Else
WDApp.Quit
End If

Set WDDoc = Nothing
Set WDApp = Nothing

End Sub

Adjust the commandbutton1 name and the drive/folder/name of the .doc file.


Anthony wrote:

Hi,
I have a workbook in Excel where I want to be able to
place a button that will print a letter that has been
created in a seperate MS Word documnet.
I have tried recording a macro but nothing happened.

Is there a way to link the two together to enable
this 'button' to produce the letter ??

Thanks

Anthony


--

Dave Peterson
  #3   Report Post  
Anthony
 
Posts: n/a
Default

Dave,

Blimey, think I follow and will give it a try,

Many thanks for your efforts

Anthony

"Dave Peterson" wrote:

I put a commandbutton from the Control Toolbox toolbar on a worksheet.

This is the code I used (double click on that commandbutton and paste this
code):

Option Explicit
Private Sub CommandButton1_Click()

'Dim WDApp As Word.Application
'Dim WDDoc As Word.Document
Dim WDApp As Object
Dim WDDoc As Object
Dim myDocName As String
Dim WordWasRunning As Boolean
Dim testStr As String

myDocName = "C:\my documents\word\document1.doc"

testStr = ""
On Error Resume Next
testStr = Dir(myDocName)
On Error GoTo 0
If testStr = "" Then
MsgBox "Word file not found!"
Exit Sub
End If

WordWasRunning = True
On Error Resume Next
Set WDApp = GetObject(, "Word.Application")
If Err.Number < 0 Then
Set WDApp = CreateObject("Word.Application")
WordWasRunning = False
End If

WDApp.Visible = True 'at least for testing!

Set WDDoc = WDApp.documents.Open(Filename:=myDocName)
WDDoc.PrintOut '.printPreview while testing???
WDDoc.Close savechanges:=False

If WordWasRunning Then
'leave it running
Else
WDApp.Quit
End If

Set WDDoc = Nothing
Set WDApp = Nothing

End Sub

Adjust the commandbutton1 name and the drive/folder/name of the .doc file.


Anthony wrote:

Hi,
I have a workbook in Excel where I want to be able to
place a button that will print a letter that has been
created in a seperate MS Word documnet.
I have tried recording a macro but nothing happened.

Is there a way to link the two together to enable
this 'button' to produce the letter ??

Thanks

Anthony


--

Dave Peterson

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
Excel 2003 Landscape Printing Problems Leena Excel Discussion (Misc queries) 1 February 22nd 05 12:44 PM
Merge mail excel to word T. Rebouche Excel Discussion (Misc queries) 2 February 21st 05 11:05 PM
Paste table from excel to word Stephen Excel Worksheet Functions 0 January 22nd 05 11:15 AM
When printing labels by using Excel data in a Word mail merge, ho. Jerry Excel Discussion (Misc queries) 2 January 2nd 05 01:27 PM
getting specific info from a word document into excel smintey Excel Discussion (Misc queries) 3 December 8th 04 08:20 PM


All times are GMT +1. The time now is 08:50 PM.

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

About Us

"It's about Microsoft Excel"