#1   Report Post  
Posted to microsoft.public.excel.programming
JRK JRK is offline
external usenet poster
 
Posts: 8
Default Slow Macro

One macro I use adds a name from a form into the header of 20-25 reports. The
procedure is called in Private Sub Worksheet_Change() as such:

'THIS LIMITS EXECUTION TO CHANGE IN SPECIFIC CELL
Dim mySheet As Worksheet
Set mySheet = Sheets("UserInfo")
Dim myName As Range
Set myName = mySheet.Range("F4")
If Not Intersect(Target, myName) Is Nothing Then
Call addHeader
End If

'THIS IS MACRO EXECUTED
Sub addHeader()
Dim Cell As Range
Dim myName, cName, myDate As String
myName = Sheets("UserInfo").Range("F4").value
cName = Sheets("UserInfo").Range("F24").value
myDate = Sheets("UserInfo").Range("F25").value
On Error Resume Next
Application.ScreenUpdating = False
Application.Calculation = xlCalculationManual
With Worksheets("Acquisition")
.PageSetup.RightHeader = "&""Tahoma,Regular""&8Prepared by: " _
& myName & ", " & myDate
.PageSetup.LeftHeader = "&""Tahoma,Regular""&8Prepared for: " _
& cName
End With
'''TOTAL OF 25 WS

The procedure takes about 10 seconds. Any ideas how I can reduce the time it
takes? TIA

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,069
Default Slow Macro

Print formatting is very slow. Try changing the default printer to "Microsoft
Office Document Image Writer" before running the macro. It should update the
header much faster. You could even retrieve the current default printer at
the beginning of your macro using Application.ActivePrinter, store it in a
string variable, change the active printer to "Microsoft Office Document
Image Writer", update the headings, then restore the original printer.

Hope this helps,

Hutch

"JRK" wrote:

One macro I use adds a name from a form into the header of 20-25 reports. The
procedure is called in Private Sub Worksheet_Change() as such:

'THIS LIMITS EXECUTION TO CHANGE IN SPECIFIC CELL
Dim mySheet As Worksheet
Set mySheet = Sheets("UserInfo")
Dim myName As Range
Set myName = mySheet.Range("F4")
If Not Intersect(Target, myName) Is Nothing Then
Call addHeader
End If

'THIS IS MACRO EXECUTED
Sub addHeader()
Dim Cell As Range
Dim myName, cName, myDate As String
myName = Sheets("UserInfo").Range("F4").value
cName = Sheets("UserInfo").Range("F24").value
myDate = Sheets("UserInfo").Range("F25").value
On Error Resume Next
Application.ScreenUpdating = False
Application.Calculation = xlCalculationManual
With Worksheets("Acquisition")
.PageSetup.RightHeader = "&""Tahoma,Regular""&8Prepared by: " _
& myName & ", " & myDate
.PageSetup.LeftHeader = "&""Tahoma,Regular""&8Prepared for: " _
& cName
End With
'''TOTAL OF 25 WS

The procedure takes about 10 seconds. Any ideas how I can reduce the time it
takes? TIA

  #3   Report Post  
Posted to microsoft.public.excel.programming
JRK JRK is offline
external usenet poster
 
Posts: 8
Default Slow Macro



"Tom Hutchins" wrote:

Print formatting is very slow. Try changing the default printer to "Microsoft
Office Document Image Writer" before running the macro. It should update the
header much faster. You could even retrieve the current default printer at
the beginning of your macro using Application.ActivePrinter, store it in a
string variable, change the active printer to "Microsoft Office Document
Image Writer", update the headings, then restore the original printer.

Hope this helps,

Hutch

Thank you, Hutch. Yes, it MS Image Writer cuts it down to about 5 seconds
(in half). But this is an application i distribute to others, so how can I be
sure they have Image Writer, and how do I know what their default printer is?
It would help if you know. Thank you.


"JRK" wrote:

One macro I use adds a name from a form into the header of 20-25 reports. The
procedure is called in Private Sub Worksheet_Change() as such:

'THIS LIMITS EXECUTION TO CHANGE IN SPECIFIC CELL
Dim mySheet As Worksheet
Set mySheet = Sheets("UserInfo")
Dim myName As Range
Set myName = mySheet.Range("F4")
If Not Intersect(Target, myName) Is Nothing Then
Call addHeader
End If

'THIS IS MACRO EXECUTED
Sub addHeader()
Dim Cell As Range
Dim myName, cName, myDate As String
myName = Sheets("UserInfo").Range("F4").value
cName = Sheets("UserInfo").Range("F24").value
myDate = Sheets("UserInfo").Range("F25").value
On Error Resume Next
Application.ScreenUpdating = False
Application.Calculation = xlCalculationManual
With Worksheets("Acquisition")
.PageSetup.RightHeader = "&""Tahoma,Regular""&8Prepared by: " _
& myName & ", " & myDate
.PageSetup.LeftHeader = "&""Tahoma,Regular""&8Prepared for: " _
& cName
End With
'''TOTAL OF 25 WS

The procedure takes about 10 seconds. Any ideas how I can reduce the time it
takes? TIA


  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,549
Default Slow Macro

A couple of changes may help...
'--
With Worksheets("Acquisition")
Application.StatusBar = "Working on " & .Name '<<<<
.DisplayPageBreaks = False '<<<<

With .PageSetUp '<<<<
.RightHeader = "&""Tahoma,Regular""&8Prepared by: " _
& myName & ", " & myDate
.LeftHeader = "&""Tahoma,Regular""&8Prepared for: " _
& cName
End With
End With
'--
The StatusBar message can keep users from getting impatient and
pounding on the keyboard.
Turning off Pagebreaks can speed things up.
Eliminating a dot can't hurt.
--
Jim Cone
Portland, Oregon USA



"JRK"
wrote in message
One macro I use adds a name from a form into the header of 20-25 reports. The
procedure is called in Private Sub Worksheet_Change() as such:

'THIS LIMITS EXECUTION TO CHANGE IN SPECIFIC CELL
Dim mySheet As Worksheet
Set mySheet = Sheets("UserInfo")
Dim myName As Range
Set myName = mySheet.Range("F4")
If Not Intersect(Target, myName) Is Nothing Then
Call addHeader
End If

'THIS IS MACRO EXECUTED
Sub addHeader()
Dim Cell As Range
Dim myName, cName, myDate As String
myName = Sheets("UserInfo").Range("F4").value
cName = Sheets("UserInfo").Range("F24").value
myDate = Sheets("UserInfo").Range("F25").value
On Error Resume Next
Application.ScreenUpdating = False
Application.Calculation = xlCalculationManual
With Worksheets("Acquisition")
.PageSetup.RightHeader = "&""Tahoma,Regular""&8Prepared by: " _
& myName & ", " & myDate
.PageSetup.LeftHeader = "&""Tahoma,Regular""&8Prepared for: " _
& cName
End With
'''TOTAL OF 25 WS

The procedure takes about 10 seconds. Any ideas how I can reduce the time it
takes? TIA

  #5   Report Post  
Posted to microsoft.public.excel.programming
JRK JRK is offline
external usenet poster
 
Posts: 8
Default Slow Macro



"Jim Cone" wrote:

A couple of changes may help...
'--
With Worksheets("Acquisition")
Application.StatusBar = "Working on " & .Name '<<<<
.DisplayPageBreaks = False '<<<<

With .PageSetUp '<<<<
.RightHeader = "&""Tahoma,Regular""&8Prepared by: " _
& myName & ", " & myDate
.LeftHeader = "&""Tahoma,Regular""&8Prepared for: " _
& cName
End With
End With
'--
The StatusBar message can keep users from getting impatient and
pounding on the keyboard.
Turning off Pagebreaks can speed things up.
Eliminating a dot can't hurt.
--
Jim Cone
Portland, Oregon USA



Thank you, Jim, but it really had little (if any) effect.




  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,549
Default Slow Macro

Ok, since changing printers worked for you,
maybe this can help you find a printer on the user machine...
'--
'Lists printers/ports in a message box.
'Printers must be on a network for this to work.
Sub ListThem()
Dim WshNetwork As Object
Dim oPrinters As Variant
Dim strPrinterList As String
Dim i As Long

Set WshNetwork = CreateObject("WScript.Network")
Set oPrinters = WshNetwork.EnumPrinterConnections
For i = 0 To oPrinters.Count - 1 Step 2
strPrinterList = strPrinterList & oPrinters.Item(i + 1) & _
" on " & oPrinters.Item(i) & vbCr
Next 'i
Set WshNetwork = Nothing
MsgBox strPrinterList
End Sub
--
Jim Cone
Portland, Oregon USA



"JRK"
wrote in message
Thank you, Jim, but it really had little (if any) effect.

  #7   Report Post  
Posted to microsoft.public.excel.programming
JRK JRK is offline
external usenet poster
 
Posts: 8
Default Slow Macro



"Jim Cone" wrote:

Ok, since changing printers worked for you,
maybe this can help you find a printer on the user machine...
'--
'Lists printers/ports in a message box.
'Printers must be on a network for this to work.
Sub ListThem()
Dim WshNetwork As Object
Dim oPrinters As Variant
Dim strPrinterList As String
Dim i As Long

Set WshNetwork = CreateObject("WScript.Network")
Set oPrinters = WshNetwork.EnumPrinterConnections
For i = 0 To oPrinters.Count - 1 Step 2
strPrinterList = strPrinterList & oPrinters.Item(i + 1) & _
" on " & oPrinters.Item(i) & vbCr
Next 'i
Set WshNetwork = Nothing
MsgBox strPrinterList
End Sub
--
Jim Cone
Portland, Oregon USA



"JRK"
wrote in message
Thank you, Jim, but it's probably not worth the effort. I had hoped for something minor. On another note. Would you know how I can let someone preview a WS in Print Preview but not print it?

  #8   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,549
Default Slow Macro

"but it's probably not worth the effort"
That why I gave you the code tweaks first.<g

I have no suggestions on not allowing printing from print preview;
--
Jim Cone
Portland, Oregon USA



"JRK"


wrote in message
Thank you, Jim, but it's probably not worth the effort. I had hoped for something minor. On another note. Would you know how I can
let someone preview a WS in Print Preview but not print it?


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
Macro is very slow jlclyde Excel Discussion (Misc queries) 2 September 29th 08 04:43 PM
slow macro John_A[_2_] Excel Programming 3 March 6th 07 06:36 PM
Very slow macro CLR Excel Programming 10 September 21st 05 12:32 PM
Slow macro alf bryn Excel Programming 5 August 5th 05 12:27 AM
Macro it's very Slow .... leo_nunez[_2_] Excel Programming 4 August 28th 04 03:45 PM


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