Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 59
Default Macro To Printout Worksheets Crashes

I'm trying to print out three sheets from different workbooks using the
printout method.

It is fine when I step through it but if I run it proper it crashes, there
seems to be some problem with the printing as nothing is printed.

Is it because the workbook is closed before printing?

I have seen a post before with the same type of question but no real answer.
I tried sleeping but that did not seem to work.

Any comments would be welcome.

Here is the code:

TIA Martin.
-------CODE------------------
Option Explicit

'---Constants---
Const cell_message As String = "D9"
Const cell_costvars_dir As String = "B5"
Const cell_airport_dir As String = "B7"
Const cell_month_mmm As String = "B10"

Const sht_apt_1 As String = "ACTUAL USD"
Const sht_apt_2 As String = "YTD USD"
Const sht_apt_3 As String = "ACTUAL USD R"

Const sht_var_2 As String = "CUM"
Const sht_var_3 As String = "Costs uscg"

Const vars_col As String = "A"
Const aprt_col As String = "B"

Const start_row As Integer = 13
'---Code---
Private Sub delaytime()
Dim i As Long
Dim a As Long
a = 0
For i = 1 To 10000
a = a + i
a = a - i
Next i
End Sub

Sub Print_Cost_Vars_And_Airport_Files()
'
' Print_Monthly_Airport_and_Cost_Vars_file Macro
'
Dim l As Long
Dim sz_month As String
Dim sz_ans As String
Dim wb As Workbook
Dim wbpath As String
Dim r As Long
Dim ws As Worksheet
On Error GoTo end_cleanup

Set ws = ActiveSheet
sz_month = Application.WorksheetFunction.Proper(ws.Range(cell _month_mmm))
If (sz_month = "Error") Then
MsgBox "Please enter a month between 1 and 12.", vbOKOnly,
"Error...", vbOKOnly
GoTo end_cleanup
ElseIf MsgBox("Are you sure you want to print files for " & sz_month &
"?", vbYesNo) = vbNo Then
GoTo end_cleanup
End If

If Right(ws.Range(cell_costvars_dir), 1) < "\" Then
ws.Range(cell_costvars_dir) = ws.Range(cell_costvars_dir) + "\"
End If
If Right(ws.Range(cell_airport_dir), 1) < "\" Then
ws.Range(cell_airport_dir) = ws.Range(cell_airport_dir) + "\"
End If

r = start_row

While (ws.Range(vars_col & r) < "" Or ws.Range(aprt_col & r) < "")

If ws.Range("B" & r) < "" Then ' print airport
Workbooks.Open ws.Range(cell_airport_dir) & _
ws.Range(aprt_col & r), False, True
Set wb = ActiveWorkbook
wb.Sheets(Array(sht_apt_1, sht_apt_2, _
sht_apt_3)).PrintOut Copies:=1, Collate:=True
delaytime
wb.Close False
End If

If ws.Range(vars_col & r) < "" Then ' print cost vars
Workbooks.Open ws.Range(cell_costvars_dir) & _
ws.Range(vars_col & r), False, True
Set wb = ActiveWorkbook
wb.Sheets(Array(sz_month, sht_var_2, _
sht_var_3)).PrintOut Copies:=1, Collate:=True
delaytime
wb.Close False
End If
r = r + 1
Wend

end_cleanup:

ws.Activate
MsgBox "Done it..."
Set ws = Nothing
Set wb = Nothing
End Sub



------CODE END-------------

--
Martin
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
Two worksheets, one printout? Rachael Excel Discussion (Misc queries) 0 June 12th 06 06:40 PM
Macro Crashes ineedhelp2[_3_] Excel Programming 1 August 18th 05 02:06 AM
Macro crashes if I run it twice Please Help Excel Programming 4 January 26th 05 10:53 PM
PrintOut macro from ?passed range.addrsess Jabba Excel Programming 1 November 2nd 04 01:53 AM
Excel crashes when copying worksheets Martien Janssen Excel Programming 1 July 5th 04 10:52 PM


All times are GMT +1. The time now is 05:40 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"