G
Greg Wilson
If I don't get a successful response I'll assume it is hopeless and move on.
Follwoing is a repost from yesterday.
Hope someone can give me an insight on what's happening here so I can come up
with an elegant fix.
Background:
I have a fairly complex Excel project that allows you to select from a large
number of picture files (100 to 500 typically) and to display a portion of
them at a time on a worksheet. You can scroll through the entire selection by
calling a UF and using a scroll bar. This has to do with photo-mapping large
flat surfaces (e.g. bridge decks) and splicing the photos together so that
you can scroll through the entire survey area. For reasons I won't go into,
existing photo-stitching software is not suitable.
Problem:
The picture scrolling process involves systematic deletion of existing
photos followed by importation of new and sizing and positioning the new.
Sounds clunky but works quite well with a minor flaw: After selecting the
photo set or after closing and reopening Excel, when you first start
scrolling there is a slight delay in inserting the new photos. Loop code is
used for this. However, once a picture has initially been inserted, when you
scroll past it (delete it) and later scroll back to it (reinsert it), the
process is much faster. It seems as though Excel remembers the photo.
Actually, it is apparently the combination of photo and specified size that
is relevant.
Insertion Specifics:
The photos are selected using GetOpenFileName and the file names are pasted
to a hidden worksheet. The configuration (number of lines of photos and
photos per
line) is specified by the user and the layout of the names on the worksheet
models the photo layout. The picture scrolling process involves deleting the
existing pictures and then importing the new pictures by refering to the file
names on in the hidden worksheet. Size and position information is handled
similarly.
Failed Efforts:
Attempts to "initialize" the photos by quickly inserting and then deleting
them (i.e. cycling through the entire series) that failed were as follows:
1) Deleting each photo immediately after inserting before inserting the next
instead of inserting all of them followed by deleting all at once.
2) Conducting the process outside of the visible range in order to hide it.
3) Conducting the process on a separate sheet in order to hide it.
4) Making them invisible.
5) Not applying the correct size (slightly smaller or bigger failed).
Successful Code:
The appended code works extremely well. After "initializing" the photos
using this code there is no delay whatsoever in the scrolling process.
However, as implied by the above failed efforts, it is apparently mandatory
that the process be conducted 'in your face' which is a nuisance. Hopefully
someone can give me an insight so I can create a more elegant solution.
Much appreciative of any help.
Regards,
Greg
Working Code:
Sub InitializePhotos()
Dim i As Long, ii As Long
Dim W As Single, H As Single, Size As Single
Dim P As Picture
Dim ShpCnt As Long
Dim Arr() As Variant
'Pocedure only called if public PhotosInitialized is False
Size = Range("Gen4") 'Named range that stores picture size
ShpCnt = ws.Shapes.Count
Application.ScreenUpdating = False
For i = 1 To UBound(PhotoList)
Set P = ws.Pictures.Insert(PhotoList(i))
If W = 0 Then
W = P.Width: H = P.Height
End If
P.Left = 0: P.Top = 0
P.Width = Size
P.Height = H / W * Size 'Preserve picture proportionality
ReDim Preserve Arr(i)
Arr(i) = i + ShpCnt
Next
DoEvents
Application.ScreenUpdating = True
ws.Unprotect
ws.Shapes.Range(Arr).Delete
ws.Protect
PhotosInitialized = True
End Sub
Follwoing is a repost from yesterday.
Hope someone can give me an insight on what's happening here so I can come up
with an elegant fix.
Background:
I have a fairly complex Excel project that allows you to select from a large
number of picture files (100 to 500 typically) and to display a portion of
them at a time on a worksheet. You can scroll through the entire selection by
calling a UF and using a scroll bar. This has to do with photo-mapping large
flat surfaces (e.g. bridge decks) and splicing the photos together so that
you can scroll through the entire survey area. For reasons I won't go into,
existing photo-stitching software is not suitable.
Problem:
The picture scrolling process involves systematic deletion of existing
photos followed by importation of new and sizing and positioning the new.
Sounds clunky but works quite well with a minor flaw: After selecting the
photo set or after closing and reopening Excel, when you first start
scrolling there is a slight delay in inserting the new photos. Loop code is
used for this. However, once a picture has initially been inserted, when you
scroll past it (delete it) and later scroll back to it (reinsert it), the
process is much faster. It seems as though Excel remembers the photo.
Actually, it is apparently the combination of photo and specified size that
is relevant.
Insertion Specifics:
The photos are selected using GetOpenFileName and the file names are pasted
to a hidden worksheet. The configuration (number of lines of photos and
photos per
line) is specified by the user and the layout of the names on the worksheet
models the photo layout. The picture scrolling process involves deleting the
existing pictures and then importing the new pictures by refering to the file
names on in the hidden worksheet. Size and position information is handled
similarly.
Failed Efforts:
Attempts to "initialize" the photos by quickly inserting and then deleting
them (i.e. cycling through the entire series) that failed were as follows:
1) Deleting each photo immediately after inserting before inserting the next
instead of inserting all of them followed by deleting all at once.
2) Conducting the process outside of the visible range in order to hide it.
3) Conducting the process on a separate sheet in order to hide it.
4) Making them invisible.
5) Not applying the correct size (slightly smaller or bigger failed).
Successful Code:
The appended code works extremely well. After "initializing" the photos
using this code there is no delay whatsoever in the scrolling process.
However, as implied by the above failed efforts, it is apparently mandatory
that the process be conducted 'in your face' which is a nuisance. Hopefully
someone can give me an insight so I can create a more elegant solution.
Much appreciative of any help.
Regards,
Greg
Working Code:
Sub InitializePhotos()
Dim i As Long, ii As Long
Dim W As Single, H As Single, Size As Single
Dim P As Picture
Dim ShpCnt As Long
Dim Arr() As Variant
'Pocedure only called if public PhotosInitialized is False
Size = Range("Gen4") 'Named range that stores picture size
ShpCnt = ws.Shapes.Count
Application.ScreenUpdating = False
For i = 1 To UBound(PhotoList)
Set P = ws.Pictures.Insert(PhotoList(i))
If W = 0 Then
W = P.Width: H = P.Height
End If
P.Left = 0: P.Top = 0
P.Width = Size
P.Height = H / W * Size 'Preserve picture proportionality
ReDim Preserve Arr(i)
Arr(i) = i + ShpCnt
Next
DoEvents
Application.ScreenUpdating = True
ws.Unprotect
ws.Shapes.Range(Arr).Delete
ws.Protect
PhotosInitialized = True
End Sub