+ Reply to Thread
Results 1 to 3 of 3

Printing MS Word Doc From MS Excel

  1. #1
    Anthony
    Guest

    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. #2
    Dave Peterson
    Guest

    Re: Printing MS Word Doc From MS Excel

    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. #3
    Anthony
    Guest

    Re: Printing MS Word Doc From MS Excel

    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 to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1