View Single Post
  #3   Report Post  
Posted to microsoft.public.excel.programming
Don Guillett Don Guillett is offline
external usenet poster
 
Posts: 10,124
Default Macro doesn't refresh

Try it this way
Sub PrintForms()
Dim StartRow As Integer
Dim EndRow As Integer
Dim Msg As String
Dim i As Integer
'==============
'new code
application.enableevents=false
ActiveWorkbook.RefreshAll
application.enableevents=false
'===========

'I don't understand a lot of the rest. What are you trying to do?
'You do NOT need to select a sheet to print it.

Sheets("PastDueList").Activate
StartRow = Range("StartRow")
EndRow = Range("EndRow")

If StartRow EndRow Then
Msg = "ERROR" & vbCrLf & "The starting row must be less than the
ending row!"
MsgBox Msg, vbCritical, APPNAME
End If

For i = StartRow To EndRow
Range("RowIndex") = i
Worksheets("Letter").Activate
'ActiveWorkbook.RefreshAll
ActiveSheet.PrintPreview
Worksheets("Statement").Activate
ActiveSheet.PrintOut
Next i
Worksheets("PastDueList").Activate
Range("RowIndex").Select
End Sub


--
Don Guillett
Microsoft MVP Excel
SalesAid Software

"JeffR" wrote in message
...
I have a spreadsheet that I'm trying to wakthrough a list of customers and
print a letter and statement for each.

I have a range named 'RowIndex' which is used by VLOOKUP statements and a
MS SQLQuery to merge some information.

The problem is that it loops through the list just fine but even though I
have auto calc on it doesn't seem to refresh the spreadsheet between
loops.

Any ideas?

Code I'm using is below.



Sub PrintForms()
Dim StartRow As Integer
Dim EndRow As Integer
Dim Msg As String
Dim i As Integer

Sheets("PastDueList").Activate
StartRow = Range("StartRow")
EndRow = Range("EndRow")

If StartRow EndRow Then
Msg = "ERROR" & vbCrLf & "The starting row must be less than the
ending row!"
MsgBox Msg, vbCritical, APPNAME
End If

For i = StartRow To EndRow
Range("RowIndex") = i
Worksheets("Letter").Activate
ActiveWorkbook.RefreshAll
ActiveSheet.PrintPreview
Worksheets("Statement").Activate
ActiveSheet.PrintOut
Next i
Worksheets("PastDueList").Activate
Range("RowIndex").Select
End Sub