Prev Previous Post   Next Post Next
  #1   Report Post  
Anthony
 
Posts: n/a
Default macro error

Hi all,
I have this code which was very kindly posted in respone to a previous
question.
Basicaly I wanted a macro to print a 'word' documnet straight from excel.

Sub LP_Tags()

'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 = "s:\lost property master sheets\sheet3.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



I have two questions
1) Can this code be any simpler or shorter ??
2) when I use this code to produce the macro the word document is opened,
but before it prints I get this error
"Word is currently Printing.Quitting will cancle all pending jobs.Do you
want to quit ? yes/no"

if I select no then the documnet is printed. Why is this happening? is there
an error in the code??

Thanks for your help

Anthony
 
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
Error trapped only while stepping through the code - Not triggered when run Jeff Excel Discussion (Misc queries) 7 March 7th 05 06:29 PM
Error trapped only while stepping through the code - Not triggered when run Jeff Excel Discussion (Misc queries) 0 February 28th 05 06:26 PM
Macro script error - pls help !! Anthony Excel Discussion (Misc queries) 3 February 28th 05 01:49 PM
run macro error, please help [email protected] Excel Discussion (Misc queries) 0 February 8th 05 03:52 AM
macro error when opening any file psp Excel Discussion (Misc queries) 1 January 31st 05 04:33 PM


All times are GMT +1. The time now is 05:27 AM.

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"