Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
John
 
Posts: n/a
Default Odd behavior on margin change

I have to loop through a significant number of charts applying numerous
changes in formats. The speed of operation is fast when I am operating my
computer stand-alone. However, when I am connect to the internet when
running my macros the speed slows down tremendeously and I can observe
significant activity on my wireless router and cable modem. The speed is
faster in the docking station at work. However, it is slower than when
stand-alone.

I narrowed down the calls that cause the slowdown and router and cable modem
activity. I want the page margins to be different than the defaults and
allow the user to set them. The following code causes the problem, which I
simplified for example:

Private Function FormatChart(oChart As Chart, ...other parameters)
With oChart
With .PageSetup
.LeftMargin = Application.InchesToPoints(0.25)
.RightMargin = Application.InchesToPoints(0.25)
.TopMargin = Application.InchesToPoints(0.25)
.BottomMargin = Application.InchesToPoints(0.25)
End With
' other code
End With
' other code
End Function

It doesn't matter whether I enter a value in points or have the app
calculate it. The workbook is self-contained, not linked to another workbook.

Any ideas?

Thanks,
John
  #2   Report Post  
Jon Peltier
 
Posts: n/a
Default

John -

Aha, now it's clear. Each chart requires four calls to the printer
driver, which is notoriously slow in Excel VBA. When your computer is
standalone, you're not hooked up to a printer, which presumably shortens
the communication loop.

The old XLM page.setup routine is much faster. I have a function I use
which runs rings around VBA's PageSetup. It builds the XLM property
string based on optional arguments supplied in the function call. It may
not be 100% debugged, but so far it's worked in a small number of my
projects. Let me know if you find a problem or think of enhancements.

' call page setup like this
bSuccess = XLM_PageSetup(<various arguments)

' XLM Page Setup Function (watch the word wrap)
''================================================ ==========================
Function XLM_PageSetup(Optional HeaderL As String = "", Optional HeaderC
As String = "", _
Optional HeaderR As String = "", Optional FooterL As String = "", _
Optional FooterC As String = "", Optional FooterR As String = "", _
Optional MarginL As Double = 0.5, Optional MarginR As Double = 0.5, _
Optional MarginT As Double = 1, Optional MarginB As Double = 1, _
Optional MarginH As Double = 0.5, Optional MarginF As Double = 0.5, _
Optional PrtRCHead As Boolean = False, Optional PrtGrid As Boolean
= False, _
Optional CtrHoriz As Boolean = True, Optional CtrVert As Boolean =
False, _
Optional PgOrient As Long = xlLandscape, Optional PaperSize As
Integer = 1, _
Optional FitToOne As Boolean = True, Optional PrtScale As Long = 100, _
Optional FitPgsWide As Integer = -1, Optional FitPgsTall As Integer
= -1, _
Optional FirstPgNum As Variant = """Auto""", Optional PgOrder As
Integer = 1, _
Optional BW As Boolean = False, Optional PrtQual As String = "", _
Optional PrtNotes As Boolean = False, Optional PrtDraft As Boolean
= False, _
Optional ChtSize As Long = xlFullPage) As Boolean

Dim sPgSetup As String
Dim sScale As String

If Not ActiveChart Is Nothing Then
sScale = ""
ElseIf FitToOne Then
sScale = "TRUE"
ElseIf FitPgsWide 0 Or FitPgsTall 0 Then
sScale = "{" & IIf(FitPgsWide 0, FitPgsWide, "#N/A") & "," &
IIf(FitPgsTall 0, FitPgsTall, "#N/A") & "}"
Else
sScale = CStr(PrtScale)
End If

sPgSetup = """&L" & HeaderL & "&C" & HeaderC & "&R" & HeaderR & ""","
sPgSetup = sPgSetup & """&L" & FooterL & "&C" & FooterC & "&R" &
FooterR & ""","
sPgSetup = sPgSetup & MarginL & "," & MarginR & "," & MarginT & "," &
MarginB & ","
If ActiveChart Is Nothing Then
sPgSetup = sPgSetup & PrtRCHead & "," & PrtGrid & ","
Else
sPgSetup = sPgSetup & ChtSize & ","
End If
sPgSetup = sPgSetup & CtrHoriz & "," & CtrVert & ","
sPgSetup = sPgSetup & PgOrient & "," & PaperSize & "," & sScale & ","
sPgSetup = sPgSetup & FirstPgNum & ","
If ActiveChart Is Nothing Then sPgSetup = sPgSetup & PgOrder & ","
sPgSetup = sPgSetup & BW & "," & PrtQual & ","
sPgSetup = sPgSetup & MarginH & "," & MarginF & ","
If ActiveChart Is Nothing Then sPgSetup = sPgSetup & PrtNotes & ","
sPgSetup = sPgSetup & PrtDraft

XLM_PageSetup = Application.ExecuteExcel4Macro("PAGE.SETUP(" &
sPgSetup & ")")
' True if successful
End Sub
''================================================ ==========================

- Jon
-------
Jon Peltier, Microsoft Excel MVP
Peltier Technical Services
Tutorials and Custom Solutions
http://PeltierTech.com/
_______


John wrote:

I have to loop through a significant number of charts applying numerous
changes in formats. The speed of operation is fast when I am operating my
computer stand-alone. However, when I am connect to the internet when
running my macros the speed slows down tremendeously and I can observe
significant activity on my wireless router and cable modem. The speed is
faster in the docking station at work. However, it is slower than when
stand-alone.

I narrowed down the calls that cause the slowdown and router and cable modem
activity. I want the page margins to be different than the defaults and
allow the user to set them. The following code causes the problem, which I
simplified for example:

Private Function FormatChart(oChart As Chart, ...other parameters)
With oChart
With .PageSetup
.LeftMargin = Application.InchesToPoints(0.25)
.RightMargin = Application.InchesToPoints(0.25)
.TopMargin = Application.InchesToPoints(0.25)
.BottomMargin = Application.InchesToPoints(0.25)
End With
' other code
End With
' other code
End Function

It doesn't matter whether I enter a value in points or have the app
calculate it. The workbook is self-contained, not linked to another workbook.

Any ideas?

Thanks,
John

  #3   Report Post  
John
 
Posts: n/a
Default

Jon,

Thanks for the post. That did the trick. I suspected that it was trying to
access the printer but couldn't figure out a method to prevent it.

I used your code "as is" and included credit. It changed the settings that
I wanted. However, I did not test all the properties.

Thanks,
John

"Jon Peltier" wrote:

John -

Aha, now it's clear. Each chart requires four calls to the printer
driver, which is notoriously slow in Excel VBA. When your computer is
standalone, you're not hooked up to a printer, which presumably shortens
the communication loop.

The old XLM page.setup routine is much faster. I have a function I use
which runs rings around VBA's PageSetup. It builds the XLM property
string based on optional arguments supplied in the function call. It may
not be 100% debugged, but so far it's worked in a small number of my
projects. Let me know if you find a problem or think of enhancements.

' call page setup like this
bSuccess = XLM_PageSetup(<various arguments)

' XLM Page Setup Function (watch the word wrap)
''================================================ ==========================
Function XLM_PageSetup(Optional HeaderL As String = "", Optional HeaderC
As String = "", _
Optional HeaderR As String = "", Optional FooterL As String = "", _
Optional FooterC As String = "", Optional FooterR As String = "", _
Optional MarginL As Double = 0.5, Optional MarginR As Double = 0.5, _
Optional MarginT As Double = 1, Optional MarginB As Double = 1, _
Optional MarginH As Double = 0.5, Optional MarginF As Double = 0.5, _
Optional PrtRCHead As Boolean = False, Optional PrtGrid As Boolean
= False, _
Optional CtrHoriz As Boolean = True, Optional CtrVert As Boolean =
False, _
Optional PgOrient As Long = xlLandscape, Optional PaperSize As
Integer = 1, _
Optional FitToOne As Boolean = True, Optional PrtScale As Long = 100, _
Optional FitPgsWide As Integer = -1, Optional FitPgsTall As Integer
= -1, _
Optional FirstPgNum As Variant = """Auto""", Optional PgOrder As
Integer = 1, _
Optional BW As Boolean = False, Optional PrtQual As String = "", _
Optional PrtNotes As Boolean = False, Optional PrtDraft As Boolean
= False, _
Optional ChtSize As Long = xlFullPage) As Boolean

Dim sPgSetup As String
Dim sScale As String

If Not ActiveChart Is Nothing Then
sScale = ""
ElseIf FitToOne Then
sScale = "TRUE"
ElseIf FitPgsWide 0 Or FitPgsTall 0 Then
sScale = "{" & IIf(FitPgsWide 0, FitPgsWide, "#N/A") & "," &
IIf(FitPgsTall 0, FitPgsTall, "#N/A") & "}"
Else
sScale = CStr(PrtScale)
End If

sPgSetup = """&L" & HeaderL & "&C" & HeaderC & "&R" & HeaderR & ""","
sPgSetup = sPgSetup & """&L" & FooterL & "&C" & FooterC & "&R" &
FooterR & ""","
sPgSetup = sPgSetup & MarginL & "," & MarginR & "," & MarginT & "," &
MarginB & ","
If ActiveChart Is Nothing Then
sPgSetup = sPgSetup & PrtRCHead & "," & PrtGrid & ","
Else
sPgSetup = sPgSetup & ChtSize & ","
End If
sPgSetup = sPgSetup & CtrHoriz & "," & CtrVert & ","
sPgSetup = sPgSetup & PgOrient & "," & PaperSize & "," & sScale & ","
sPgSetup = sPgSetup & FirstPgNum & ","
If ActiveChart Is Nothing Then sPgSetup = sPgSetup & PgOrder & ","
sPgSetup = sPgSetup & BW & "," & PrtQual & ","
sPgSetup = sPgSetup & MarginH & "," & MarginF & ","
If ActiveChart Is Nothing Then sPgSetup = sPgSetup & PrtNotes & ","
sPgSetup = sPgSetup & PrtDraft

XLM_PageSetup = Application.ExecuteExcel4Macro("PAGE.SETUP(" &
sPgSetup & ")")
' True if successful
End Sub
''================================================ ==========================

- Jon
-------
Jon Peltier, Microsoft Excel MVP
Peltier Technical Services
Tutorials and Custom Solutions
http://PeltierTech.com/
_______


John wrote:

I have to loop through a significant number of charts applying numerous
changes in formats. The speed of operation is fast when I am operating my
computer stand-alone. However, when I am connect to the internet when
running my macros the speed slows down tremendeously and I can observe
significant activity on my wireless router and cable modem. The speed is
faster in the docking station at work. However, it is slower than when
stand-alone.

I narrowed down the calls that cause the slowdown and router and cable modem
activity. I want the page margins to be different than the defaults and
allow the user to set them. The following code causes the problem, which I
simplified for example:

Private Function FormatChart(oChart As Chart, ...other parameters)
With oChart
With .PageSetup
.LeftMargin = Application.InchesToPoints(0.25)
.RightMargin = Application.InchesToPoints(0.25)
.TopMargin = Application.InchesToPoints(0.25)
.BottomMargin = Application.InchesToPoints(0.25)
End With
' other code
End With
' other code
End Function

It doesn't matter whether I enter a value in points or have the app
calculate it. The workbook is self-contained, not linked to another workbook.

Any ideas?

Thanks,
John


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
conditional cell shading when a change occurs zooeyhall Excel Discussion (Misc queries) 1 June 6th 05 05:14 PM
How do you change the right margin of a header in Excel? ncford Excel Discussion (Misc queries) 5 January 20th 05 03:17 AM
Change Margin Defaults Amanda Setting up and Configuration of Excel 1 January 15th 05 12:56 AM
how do i make a date change automatically if i change one before . dpl7579 Excel Discussion (Misc queries) 1 January 11th 05 09:21 PM
Right margin will not change. Venissa Excel Worksheet Functions 0 October 28th 04 08:15 PM


All times are GMT +1. The time now is 10:22 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"