Resizing of picture different in run time and design time

B

Broadband-Al

Very odd. I have a simple macro to resize all the pictures on a page in
order to fit the page breaks. It works perfectly when I step through the
code, line by line using "F8" but if I leave it to run from a command button
on the sheet, the pictures do resize but to a completely different dimension
than instructed.

After resetting pagebreaks, the code is simply a for next loop with:

AcvtiveSheet.Shapes(i).Select
With Selection
.ShapeRange.LockAspectRatio = msoTrue
.ShapeRange.Height = ht
.ShapeRange.Top = yposn
.ShapeRange.Left = xposn
End With
 
J

Joel

the problem probably isn't in the loop you posted. I would need to see the
entire code to spot the problem. You are probably get the the szie from the
wrong source location. Probably from a different worksheet.
 
B

Broadband-Al

Thanks - have found that if I change the Screenupdating = true then the
problem goes away. This is good but for the future, I am no wiser as to why
the scaling should change just because of the screenupdating property. I've
not used the scaleheight property anywhere... Here's the full code:

ActiveSheet.PageSetup.Orientation = xlPortrait
ActiveSheet.ResetAllPageBreaks

'set options - borders and no. pics on page
interval = 6 'gap between images
NoOnPage = InputBox("No. pictures per page?", "Picture Lay-Out", 4) 'no
of pictures per page

'Find row and column with breaks
BreakR = activesheet.HPageBreaks(1).Location.Row
BreakC = activesheet.VPageBreaks(1).Location.Column

'Find no. points to breaks
pagelength = ActiveSheet.Cells(BreakR, 1).Top
pagewidth = ActiveSheet.Cells(1, BreakC).Left

'Set picture height
ht = (pagelength - interval * NoOnPage) / NoOnPage

'So lets fit them - first at.....
yposn = interval / 2
Application.ScreenUpdating = True

For i = 1 To NoPics
'Resize first
activesheet.Shapes(PicOrder(i)).Select
With Selection
.ShapeRange.LockAspectRatio = msoTrue
.ShapeRange.Height = ht
End With

'now choose x position: odds centred left - evens centred right
If i Mod 2 > 0 Then
'odd number
xposn = 7
Else
'even number
xposn = pagewidth - Selection.ShapeRange.Width - 7
End If

'now locate pic
With Selection
.ShapeRange.Top = yposn
.ShapeRange.Left = xposn
End With

yposn = yposn + ht + interval 'set top position ready for next pic

Next i
 
J

Joel

If screen updating is off then this line doesn't get changed

xposn = pagewidth - Selection.ShapeRange.Width - 7

The Width is still the old value since the screen did get updated.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top