Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
DiscussionsAccessExcelInfoPathOutlookPowerPointPublisherWord
DirectoryUser Groups
Related Topics
Outlook ExpressInternet ExplorerWindowsMS Server ProductsMore Topics ...

MS Office Forum / General PowerPoint Questions / September 2007

Tip: Looking for answers? Try searching our database.

dynamic embedded interactive menus in powerpoint presentation: Part II the crude solution

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Incredulous Dreamer - 23 Sep 2007 06:53 GMT
OK,  Here is my first attempt to solve the problem I posted a couple days
back.  It is functional but I am sure it is not as elegant as it could be,
because I am just a code hacker.  My thanks to Steve Rindsberg and David
Marcovitz for setting me down the path.

Some troubles I had and what I learned:
  1) It was necessary to be able to allow the user to toggle the selection
boxes "on and off" repeatedly.  So, the only thing I could think of to do
was update the box status for all the boxes and rewrite the entire text file
every time the user changed ANY selection box.  If there is a more elegent
way to do this, please let me know.
2)  Now I believe I know why David used the
        Set fs = CreateObject("Scripting.FileSystemObject")
       Set answerFile = fs.CreateTextFile("C:\Documents .......
methods in his quiz code.  That seems to be the only method I could use that
would overwrite the file each time.  I couldn't find a way to do that with
the "open" method.
3)  I don't "read" the value for the comboBox yet, I haven't figured out
that command yet but I hope to accomplish that without much additional
grief.

Next I need to bring the txt file created into specific cells in a
spreadsheet.  In future versions some of the response may be numbers but I
assume I can deal with that as well.

The code follows below.  Improvements are welcome.

Private Sub UserForm_Initialize()
   ComboBox1.Clear
   ComboBox1.ColumnCount = 2
   ComboBox1.BoundColumn = 2
   ComboBox1.TextColumn = 1

   ComboBox1.AddItem "Low"
   ComboBox1.AddItem "Medium"
   ComboBox1.AddItem "High"

   ListBox1.AddItem "Beam Blanker"
   ListBox1.ColumnCount = 1
   ListBox1.BoundColumn = 1
   ListBox1.TextColumn = 4

   End Sub
Public Sub ListBox1_Change()
       Set fs = CreateObject("Scripting.FileSystemObject")
       Set answerFile = fs.CreateTextFile("C:\Documents and
Settings\Desktop\powerpoint VB files\answers.txt", True)
       answerFile.Close
       ListBox2.AddItem "Electron Lithography"
       ListBox2.ColumnCount = 1
       ListBox2.BoundColumn = 1

       Open "C:\Documents and Settings\Desktop\powerpoint VB
files\answers.txt" For Output As #1

       If ListBox1.Selected(0) = True Then

           Write #1, "Beam Blanker"
       Else
           Write #1, "No Beam Blanker"

       End If

       If ListBox2.Selected(0) = True Then
           Write #1, "Electron Lithography"
       Else
           Write #1, "No Electron Lithograpy"
       End If
       If ListBox3.Selected(0) = True Then
           Write #1, "Ion Lithography"
       Else
           Write #1, "No Ion Lithography"
       End If
       If ListBox4.Selected(0) = True Then
           Write #1, "TEM Sample Preparation"
       Else
           Write #1, "No TEM Sample Prep"
       End If

       Close #1
End Sub
Private Sub ListBox2_Change()
       Set fs = CreateObject("Scripting.FileSystemObject")
       Set answerFile = fs.CreateTextFile("C:\Documents and
Settings\Desktop\powerpoint VB files\answers.txt", True)
       answerFile.Close

       ListBox3.AddItem "ion Lithography"
       ListBox3.ColumnCount = 1
       ListBox3.BoundColumn = 1
       Open "C:\Documents and Settings\Desktop\powerpoint VB
files\answers.txt" For Output As #1
       If ListBox1.Selected(0) = True Then

           Write #1, "Beam Blanker"
       Else
           Write #1, "No Beam Blanker"

       End If

       If ListBox2.Selected(0) = True Then
           Write #1, "Electron Lithography"
       Else
           Write #1, "No Electron Lithograpy"
       End If
       If ListBox3.Selected(0) = True Then
           Write #1, "Ion Lithography"
       Else
           Write #1, "No Ion Lithography"
       End If
       If ListBox4.Selected(0) = True Then
           Write #1, "TEM Sample Preparation"
       Else
           Write #1, "No TEM Sample Prep"
       End If

       Close #1
End Sub
Private Sub ListBox3_Change()
       Set fs = CreateObject("Scripting.FileSystemObject")
       Set answerFile = fs.CreateTextFile("C:\Documents and
Settings\Desktop\powerpoint VB files\answers.txt", True)
       answerFile.Close
       ListBox4.AddItem "TEM Sample Preparation"
       ListBox4.ColumnCount = 1
       ListBox4.BoundColumn = 1
       Open "C:\Documents and Settings\Desktop\powerpoint VB
files\answers.txt" For Output As #1
       If ListBox1.Selected(0) = True Then

           Write #1, "Beam Blanker"
       Else
           Write #1, "No Beam Blanker"

       End If

       If ListBox2.Selected(0) = True Then
           Write #1, "Electron Lithography"
       Else
           Write #1, "No Electron Lithograpy"
       End If
       If ListBox3.Selected(0) = True Then
           Write #1, "Ion Lithography"
       Else
           Write #1, "No Ion Lithography"
       End If
       If ListBox4.Selected(0) = True Then
           Write #1, "TEM Sample Preparation"
       Else
           Write #1, "No TEM Sample Prep"
       End If

       Close #1
End Sub
Private Sub ListBox4_Change()
       Set fs = CreateObject("Scripting.FileSystemObject")
       Set answerFile = fs.CreateTextFile("C:\Documents and
Settings\Desktop\powerpoint VB files\answers.txt", True)
       answerFile.Close
       Open "C:\Documents and Settings\Desktop\powerpoint VB
files\answers.txt" For Output As #1

       If ListBox1.Selected(0) = True Then

           Write #1, "Beam Blanker"
       Else
           Write #1, "No Beam Blanker"

       End If

       If ListBox2.Selected(0) = True Then
           Write #1, "Electron Lithography"
       Else
           Write #1, "No Electron Lithograpy"
       End If
       If ListBox3.Selected(0) = True Then
           Write #1, "Ion Lithography"
       Else
           Write #1, "No Ion Lithography"
       End If
       If ListBox4.Selected(0) = True Then
           Write #1, "TEM Sample Preparation"
       Else
           Write #1, "No TEM Sample Prep"
       End If

       Close #1
End Sub
Steve Rindsberg - 23 Sep 2007 18:52 GMT
> Some troubles I had and what I learned:
>    1) It was necessary to be able to allow the user to toggle the selection
> boxes "on and off" repeatedly.  So, the only thing I could think of to do
> was update the box status for all the boxes and rewrite the entire text file
> every time the user changed ANY selection box.  If there is a more elegent
> way to do this, please let me know.

If it's only a small amount of data, writing text files can be insanely fast on
today's computers.  If it's not slowing things down, it may not be worth making
elegant.  The old "If it ain't broke ..." thing.

> 2)  Now I believe I know why David used the
>          Set fs = CreateObject("Scripting.FileSystemObject")
>         Set answerFile = fs.CreateTextFile("C:\Documents .......
> methods in his quiz code.  That seems to be the only method I could use that
> would overwrite the file each time.  I couldn't find a way to do that with
> the "open" method.

With straight VBA, you'd use KILL on the file to delete it, then rewrite it.

Give us a shout if you have trouble reading the combo.  Some example code here:

Manipulating Listbox and Combobox controls on slides
http://www.pptfaq.com/FAQ00439.htm

> Next I need to bring the txt file created into specific cells in a
> spreadsheet.  In future versions some of the response may be numbers but I
> assume I can deal with that as well.

I think I may've mentioned writing the data out to a CSV file rather than just
text.  Nothing really tricky there, just a matter of putting the quotes and
commas around each record.  And Excel will eat them directly.


> The code follows below.  Improvements are welcome.
>
[quoted text clipped - 159 lines]
>         Close #1
> End Sub

-----------------------------------------
Steve Rindsberg, PPT MVP
PPT FAQ:  www.pptfaq.com
PPTools:  www.pptools.com
================================================
Incredulous Dreamer - 24 Sep 2007 15:51 GMT
Well, I am having a few more problems understanding the information you
provided.

I tried running both the examples you provided a link to in the message
below and neither ran successfully, both having trouble with the same part
of the code:
   Set oShape = ActiveWindow.Selection.ShapeRange(1)

both errors are similar:
1)    Selection (unknown member): Invalid request.  Nothing appropriate is
currently selected.

2)  Selection (unknown member): Invalid request. This view does not support
selection.

I also have two questions:

1)  When running in presentation mode how do I get the code (macro) to run
automatically when the slide is brought up in the presentation.  In other
words, I'd like the code to run either when the presentation is started
automatically, or when the slide on which the code module is in, is
selected.
2)  When I am trying to read, write or manipulate the contents of a listbox
or combobox, I don't understand the code to reference that object by name
(rather than being selected by the mouse).  That may be the problem (or one
of) the code and my errors.  It looks like the code is based upon an active
window and the currently selected object.  What I want is to refer to a
specfic object (i.e., ListBox_1 ) and manipulate that object (read the name
of an item in that box that was selected for instance, or the text name of
that object.  Also, my sub routine " Sub Initialize UserForm() doesn't
appear in any list of macros.

Clearly there are gaps in my knowledge and I believe I am missing something
very basic.  Thanks for your patience.

-Ed

>> Some troubles I had and what I learned:
>>    1) It was necessary to be able to allow the user to toggle the
[quoted text clipped - 210 lines]
> PPTools:  www.pptools.com
> ================================================
Steve Rindsberg - 24 Sep 2007 23:04 GMT
> Well, I am having a few more problems understanding the information you
> provided.
[quoted text clipped - 10 lines]
> 2)  Selection (unknown member): Invalid request. This view does not support
> selection.

The example code simply works on the currently selected shape. If nothing's
selected, you'll get that sort of error.

> 1)  When running in presentation mode how do I get the code (macro) to run
> automatically when the slide is brought up in the presentation.  In other
> words, I'd like the code to run either when the presentation is started
> automatically, or when the slide on which the code module is in, is
> selected.

Have a look here:

How can I get my code to run automatically when a presentation opens?
http://www.pptfaq.com/FAQ00741.htm

> 2)  When I am trying to read, write or manipulate the contents of a listbox
> or combobox, I don't understand the code to reference that object by name
> (rather than being selected by the mouse).  That may be the problem (or one
> of) the code and my errors.  It looks like the code is based upon an active
> window and the currently selected object.  

Correct.  So what you want to do is:

Set oShape = ActivePresentation.Slides(x).Shapes("ListBox_1")
(substituting the correct slide index for x)

What I want is to refer to a
> specfic object (i.e., ListBox_1 ) and manipulate that object (read the name
> of an item in that box that was selected for instance, or the text name of
[quoted text clipped - 220 lines]
> > PPTools:  www.pptools.com
> > ================================================

-----------------------------------------
Steve Rindsberg, PPT MVP
PPT FAQ:  www.pptfaq.com
PPTools:  www.pptools.com
================================================
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.