TCARPENTER
Programmer
I'm so close on this one it's driving me crazy. I have a directory of thumbnail images I'm importing to a Power Point sheet. What I'm trying to do is build a simple grid of images based on the sheet size, image size and spacing. I'm just a tad off (especially between the first and second columns) and I can't figure out what I'm doing wrong, I'm sure it's in my loop somewhere. Any ideas:
Thanks for any help!
Code:
Sub CreateTOC()
Dim oSlide As Slide
Dim oSlides As Slides
Dim sImage As String
Dim sImages() As String
Dim iCnt As Integer
Dim iPos As Integer
Dim iTot As Integer
Dim oLayout As CustomLayout
Dim oShape As Shape
Dim sTitle As String
Dim cPath As New cStdPath
Dim dOH As Double 'Overall Height of page.
Dim dOW As Double 'Overall Width of page.
Dim dVS As Double 'Verical Spacing between images.
Dim dHS As Double 'Horizontal Spacing between images.
Dim dTp As Double 'Top point for thumbnail.
Dim dLt As Double 'Left point for thumbnail.
' Dim dColHgt As Double 'Column height.
Dim dRowWid As Double 'Row width.
Dim iColCnt As Integer
Dim dCurrColWid As Double
Dim dLastColWid As Double
Dim dLastShpHgt As Double
Dim dLastShpWid As Double
sImage = Dir("C:\Images\", vbNormal)
Set oSlides = ActivePresentation.Slides
Set oLayout = ActivePresentation.Slides(2).CustomLayout
Do While sImage <> ""
AddToStringArray sImages, sImage
sImage = Dir
iTot = iTot + 1
Loop
' Debug.Print "Total images: " & iTot
' Calculate starting point?
Set oSlide = oSlides(2)
dOH = oSlide.CustomLayout.height
dVS = 25
dOW = oSlide.CustomLayout.width
dHS = 25
' Debug.Print "Overall Sheet Height: " & dOH
' Debug.Print " Vertical spacing: " & dVS
' Debug.Print " Overall Sheet Width: " & dOW
' Debug.Print " Horizontal spacing: " & dHS
iColCnt = 1
For iCnt = LBound(sImages) To UBound(sImages)
' Debug.Print iCnt & " = " & sImages(iCnt)
Set oShape = oSlide.Shapes.AddPicture("C:\Images\" & sImages(iCnt), msoFalse, msoTrue, 0, 0)
' Debug.Print oShape.width
' Debug.Print oShape.height
'Resize the thumbnail to 1" height max.
'
If oShape.height < oShape.width Then
oShape.width = 75
Else
oShape.height = 75
End If
If iCnt = LBound(sImages) Then
dLastShpHgt = oShape.width
dLastShpWid = oShape.height
End If
'Reset the current column width to
'the widest shape.
'
If oShape.width > dCurrColWid Then
dCurrColWid = oShape.width
dLastColWid = dCurrColWid
If iColCnt = 1 Then
dRowWid = dHS + dCurrColWid
Else
dRowWid = (dRowWid + dCurrColWid) - dLastColWid
End If
Debug.Print dRowWid
End If
'Set the start points.
'
If iCnt = LBound(sImages) Then
dTp = dVS
dLt = dHS
dRowWid = dHS + dCurrColWid
Else
dTp = dTp + (dLastShpHgt + dVS)
End If
' Check image does not extend beyond the bottom of the page,
' if it's going to, add a new column.
'
If dTp + oShape.height >= dOH Then
iColCnt = iColCnt + 1 'Increment the column counter.
dTp = dVS 'Reset the top thumbnail insertion point.
dLt = dRowWid + dLastShpWid 'Reset the left thumbnail insertion point.
dRowWid = dRowWid + dHS 'Reset the total row width.
dCurrColWid = 0 'Reset the current column width.
End If
' Check image does extend beyond the rightmost edge of the page,
' if it does, add a new sheet.
'
If dRowWid + oShape.width >= dOW Then
dRowWid = 0
oShape.Delete
Set oSlide = oSlides.AddSlide(oSlides.Count + 1, oLayout)
Set oShape = oSlide.Shapes.AddPicture("C:\Images\" & sImages(iCnt), msoFalse, msoTrue, 0, 0)
'Resize the thumbnail to 1" height max.
'
If oShape.height < oShape.width Then
oShape.width = 75
Else
oShape.height = 75
End If
iColCnt = 1 'Reset the column counter.
dTp = dVS 'Reset the top thumbnail insertion point.
dLt = dHS 'Reset the left thumbnail insertion point.
dRowWid = dHS + dCurrColWid 'Reset the total row width.
dCurrColWid = 0 'Reset the current column width.
End If
' Place the thumbnail
'
oShape.Top = dTp
oShape.Left = dLt
oShape.ZOrder msoSendToBack
If iCnt <> LBound(sImages) Then
dLastShpHgt = oShape.width
dLastShpWid = oShape.height
End If
Next
End Sub
Thanks for any help!