Home |
Search |
Today's Posts |
#1
![]() |
|||
|
|||
![]()
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
![]() |
|||
|
|||
![]()
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
![]() |
|||
|
|||
![]()
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 |
Display Modes | |
|
|
![]() |
||||
Thread | Forum | |||
Excel 2003 Landscape Printing Problems | Excel Discussion (Misc queries) | |||
Merge mail excel to word | Excel Discussion (Misc queries) | |||
Paste table from excel to word | Excel Worksheet Functions | |||
When printing labels by using Excel data in a Word mail merge, ho. | Excel Discussion (Misc queries) | |||
getting specific info from a word document into excel | Excel Discussion (Misc queries) |