#1
|
|||
|
|||
User form Help
I have created a UserForm so that I can search my powerpoint slide during the presentation. I am trying to figure out how to code the command button "Next" on the userform to take me to the next time the searched word is found in the presentation. The code I am currently using is
Code:
Private Sub FCnext_Click() If TextBox1 = True Then If Me.TextBox1.Text <> "" Then SlideShowWindows(1).View.GotoSlide (osld.SlideIndex) End If End If End Sub Private Sub TextBox1_KeyDown(ByVal KeyCode As MSForms.ReturnInteger, ByVal Shift As Integer) Dim osld As Slide Dim oshp As Shape Dim b_found As Boolean If KeyCode = 13 Then 'ENTER PRESSED If Me.TextBox1.Text <> "" Then For Each osld In ActivePresentation.Slides For Each oshp In osld.Shapes If oshp.HasTextFrame Then If oshp.TextFrame.HasText Then If InStr(UCase(oshp.TextFrame.TextRange), UCase(Me.TextBox1.Text)) > 0 Then SlideShowWindows(1).View.GotoSlide (osld.SlideIndex) Me.TextBox1.Text = "" b_found = True Exit For End If End If End If Next oshp If b_found = True Then Exit For Next osld End If If b_found = False Then MsgBox "Not found" End If End Sub Thank you for any help. Last edited by macropod; 07-22-2015 at 06:32 PM. Reason: Added code tags & formatting |
#2
|
|||
|
|||
Maybe this (you could easily add the keydown sub but it's not needed. Might need a little edit to get the all found correct.
Code:
Dim SldINX As Long Private Sub UserForm_Initialize() Me.FCnext.Caption = "Find" End Sub Private Sub FCnext_Click() If SldINX = 0 Then SldINX = 1 Me.FCnext.Caption = "Next" Call searchSlide(SldINX) End Sub Sub searchSlide(fromSld As Long) Dim oshp As Shape Dim osld As Slide Dim Counter As Long Dim b_found As Boolean If SldINX > ActivePresentation.Slides.Count Then MsgBox "Done" Unload UserForm1 Exit Sub End If For Counter = fromSld To ActivePresentation.Slides.Count Set osld = ActivePresentation.Slides(Counter) For Each oshp In osld.Shapes If oshp.HasTextFrame Then If oshp.TextFrame.HasText Then If InStr(UCase(oshp.TextFrame.TextRange), UCase(Me.TextBox1.Text)) > 0 Then SlideShowWindows(1).View.GotoSlide (osld.SlideIndex) b_found = True SldINX = Counter + 1 Exit For End If End If End If Next oshp If b_found Then Exit For Next Counter If b_found = False Then SlideShowWindows(1).View.GotoSlide (ActivePresentation.Slides.Count) MsgBox "Not Found" Me.TextBox1.Text = "" SldINX = 1 Unload UserForm1 End If End Sub Last edited by JohnWilson; 07-23-2015 at 04:30 AM. |
#3
|
|||
|
|||
Awesome!
Thank you so much. That worked perfectly, Now that it is working tho it showed me that I need to either highlight the found text or put a box around it so that it stands out on the slide. This presentation is very heavy with information so search thru the slides it pulls up can be a job in itself. Is this easily added to the code?
|
#4
|
|||
|
|||
This is straight off the top of my head but it might work
Code:
Dim SldINX As Long Private Sub UserForm_Initialize() Me.FCnext.Caption = "Find" End Sub Private Sub FCnext_Click() If SldINX = 0 Then SldINX = 1 Me.FCnext.Caption = "Next" Call searchSlide(SldINX) End Sub Sub searchSlide(fromSld As Long) Dim oshp As Shape Dim osld As Slide Dim Counter As Long Dim b_found As Boolean Dim oTxtTemp As TextRange Dim strFind As String On Error Resume Next For Each osld In ActivePresentation.Slides osld.Shapes("redBox").Delete Next osld If SldINX > ActivePresentation.Slides.Count Then MsgBox "Done" Unload UserForm1 Exit Sub End If strFind = Me.TextBox1.Text For Counter = fromSld To ActivePresentation.Slides.Count Set osld = ActivePresentation.Slides(Counter) For Each oshp In osld.Shapes If oshp.HasTextFrame Then If oshp.TextFrame.HasText Then Set oTxtTemp = oshp.TextFrame.TextRange.Find(strFind, , False) If Not oTxtTemp Is Nothing Then SlideShowWindows(1).View.GotoSlide (osld.SlideIndex) With osld.Shapes.AddShape(msoShapeRectangle, oTxtTemp.BoundLeft, oTxtTemp.BoundTop, oTxtTemp.BoundWidth, oTxtTemp.BoundHeight) .Fill.Visible = False .Line.ForeColor.RGB = vbRed .Name = "redBox" End With b_found = True SldINX = Counter + 1 Exit For End If End If End If Next oshp If b_found Then Exit For Next Counter If b_found = False Then SlideShowWindows(1).View.GotoSlide (ActivePresentation.Slides.Count) MsgBox "Not Found" Me.TextBox1.Text = "" SldINX = 1 Unload UserForm1 End If End Sub |
#5
|
|||
|
|||
Again, Perfect
Thank you so Much. You really made helped me out. Thank you the code works perfectly.
|
#6
|
|||
|
|||
Mr Wilson maybe you could help me out again. This might be easier than my previous need, which i greatly appreciate your help.
I have 3 monitors that I am using set up in a pyramid 2 on bottom and a 55" display above. When I go to the slide show and run the userform they do not appear on the same screen. I tried to use the properties postion but when I center it it puts it in the middle of all 3 screens. I also tried the following code Code:
Private Sub FastConnectSearch_Initialize() Dim TopOffset As Integer Dim LeftOffset As Integer TopOffset = (Application.UsableHeight / 2) - (Me.Height / 2) LeftOffset = (Application.UsableWidth / 2) - (Me.Width / 2) Me.Top = Application.Top + TopOffset Me.Left = Application.Left + LeftOffset End Sub |
#7
|
|||
|
|||
Document
@johnwilson
I have added a skeleton of the presentation that I am working on. Please understand that for legal reasons I cannot post the document with all the proprietary content. But I figured it would give you a better idea of what I am attempting to accomplish. The presentation is distributed as a Macro enabled show only and is used as basically a contact database with hundreds if not thousands of contacts and numbers and departments. As you can vaguely see (due to me having to remove the smart boxes and quite a bit of content) I have placed labels that are coded to take me to slides in presentation when in the show view. The search button at the top, coded by you, works perfectly and the red box is perfect. The only other thing I could ask is for a bit of help on the label coding. They work effectively enough but with the amount of information on each give slide the some labels are required to go to actual parts of a slide much like the search feature. I have been attempting to use your Redbox code modified to have a somewhat large, noticeable Red circle next the label information on the slide. For example slide 7 has the words Zone 2 and Zone 3. The two labels on the home page take you to that slide from the code but I would like the Red circle to show and then disappear if that corresponding label is pushed. I apologize for the continued request for help, I am attempting to make this presentation as user friendly as possible and have put in dozens of hours entering information and have just hit a wall. It doesn’t help that I am new to VBA coding and teaching myself as I go. Please any help would be greatly appreciated. Last edited by JMer; 07-24-2015 at 06:22 PM. Reason: Removed info from presentation |
Tags |
userform, vba, vba powerpoint |
|
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
VBA to save word user form value to xml | Rose roon | Word VBA | 25 | 06-23-2015 04:35 AM |
User Form - Close Paragraphs | SonyaEnz | Word VBA | 4 | 06-05-2015 06:16 AM |
User form | abdulgani | Excel | 0 | 12-15-2014 05:54 AM |
User Form | placasse47 | Excel Programming | 3 | 08-01-2012 05:57 AM |
Controlling Style when a user pastes into a form | Cris0205 | Word | 0 | 08-05-2010 04:33 PM |