LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 747
Default Repost: Speed of inserting pictures and Excel memory

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

 
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
Inserting pictures into Excel Sheet at a particular size ToferKing Excel Discussion (Misc queries) 5 February 25th 10 07:03 PM
Speed of Excel When Inserting & Deleting Rows Gerry Excel Discussion (Misc queries) 13 March 5th 08 04:04 AM
Inserting pictures in Excel 2003 jawone48 Excel Discussion (Misc queries) 6 August 11th 07 06:17 AM
Excel memory and speed when inserting pictures ??? Greg Wilson Excel Programming 2 September 14th 05 09:01 AM
Memory Leak Excel 2003 vs 2000 using linked pictures Scriptick Excel Programming 0 April 27th 05 04:16 PM


All times are GMT +1. The time now is 01:20 AM.

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"