Using ListBox in macro

  • Thread starter Thread starter Chris Watts
  • Start date Start date
C

Chris Watts

Can somebody please point me at a good example of Creating, Populating,
Displaying and Extracting user's selection using a ListBox from within a VBA
macro.

TIA
Chris
 
Hi John,
No not part of a form. I wish to create it directly on the slide for input
purposes and then kill it.

I think that I have figured out (using your reference) how to populate the
list (using .AddList) but cannot see it appear on the slide.

cheers
Chris
 
Thanks Steve - that did it.

It works fine with a predefined listbox. Now I have to figure out how to
get the box listbox to appear/dissappear as needed. Guess altering the fill
to/from background colour (or even color ;) ) ought to do that. Then I need
to learn how to extract the selection from it.

What I am working on is extend the Agenda/Menu program so that it (a)
operates only on the current slide and (b) will on update ask you to choose
from the current directory or a list of subdirectories containing
presentations or links to them. Several usage possibilities. The
conference one where you can have subdirectories for each day/session or for
a personal mini-library.

Great learning experience.

Many thanks
Chris
 
Thanks Steve. That works just great.
But still haven't figured out how to access the index of the item selected
or clicked-on by the user - guidance welcome!
cheers
Chris
 
Hi Steve,
Thanks for your patience and advice - it is much appreciated.
I find it incredibly frutrating trying to get to grips with vba as all the
written
guides are for something other than ppt or ...

I have tried what you suggest but no luck - when used as a prive sub it
objects to the Me. object.
Presumably that is because I have ListBox1 on the slide and not as part of a
form??? If I leave it out then it says that ListBox1 is undefined.

So I tried putting MsgBox statements in the main subroutine within the scope
of the With's that you suggested, namely:

With ActivePresentation.Slides(iWhere).Shapes("ListBox1")
With .OLEFormat.Object
.Clear
' Add items to the list
For k = 1 To j
.AddItem (strDirList(k, 1))
Next
.Height = 80
.ForeColor = RGB(255, 0, 0)
.BackColor = RGB(0, 0, 0)
.BorderColor = RGB(0, 0, 255)
.Visible = True
MsgBox (.Text)
MsgBox (.ListIndex)
End With
End With


That works fine but displays simply "" and -1 - ie before anything is
clicked/changed in the ListBox. I cannot see how I should make it wait for
a change event. I tried preceding the MsgBox statements with a While
..ListIndex = -1 Wend
That, predicably, sends the module into an indefinite loop!
So the next question ;-)) is how do you await the change event?
cheers.
Chris
 
Hi again, Steve,
I have found one solution - don't know how elegenat it is:

Dim WAIT As Double
With ActivePresentation.Slides(iWhere).Shapes("ListBox1")
With .OLEFormat.Object
..Visible = True

RefreshSlide
While .ListIndex = -1
WAIT = Timer
While Timer < WAIT + 2
DoEvents 'do nothingWend
Wend
Wend
MsgBox (.Text)
MsgBox (.ListIndex)
End With
End With

All within your magic While's. RefreshSlide is an already defined sub

cheers
Chris
 
Many, many thanks Steve.
I have done what you suggested.
I have now got it all working to my satisfaction.
cheers
Chris
 
Back
Top