![]() |
|
|
|
#1
|
|||
|
|||
|
Thank you very much for your time and expertise! It really means a lot.
I haven't had a chance to sit down and go through your posts in detail as I'm up to my eyes in work. I hope to get some time later this evening to go through it. I will let you know how I get on. Thanks again! |
|
#2
|
|||
|
|||
|
excelledsoftware, thank you very much for your time and expertise.
I have ran the final VBA code you posted and it works like a dream! I have also been going down through the code and re-writing it into VBA to familiarize myself with it and gain an understanding of writing the code. However, I have tried to run the first macro: GetTheLineColors but with no end result. I must be missing a step in the process; I definitely have the code correct, definitely ran the macro and I have enabled the macro security settings. I don't see any result to 'paste into Excell'. Any further help you can offer is greatly appreciated. |
|
#3
|
|||
|
|||
|
Glad it worked out. Anytime you see the phrase debug.print in a block of a code it means that it is writing it to the immediate window. To see this window go to view in your visual basic editor and click the immediate window button. When you run the code you will see the results in this new window.
|
|
#4
|
|||
|
|||
|
Well done Mr Excelled!
Where are you based? |
|
#5
|
|||
|
|||
|
Oh my! that means so much coming from you. I am based in the US.
|
|
#6
|
|||
|
|||
|
Steve Rindsberg and I are running the Help Centre at the Presentation Summit in San Diego this October. If you're a PowerPoint Pro this is the very best conference!
|
|
#7
|
|||
|
|||
|
Wow! I will have to keep it in mind. I wouldn't call my self a pro but I do like to use PPT and VBA.
|
|
#8
|
|||
|
|||
|
excelledsoftware, I hope you don't mind me asking a bunch of questions but learning how to use VBA coding will often save me quite a bit of time.
I have been adapting your sub routine to change certain lines to different colors individually with no problem. However, in learning to use VBA properly I am trying to write code that will do this all at once and have ran into a bit of bother. I have attached the PowerPoint file which I have been practicing on. This is the code I've been trying to use to change multiple line colors and also the line weight of the black lines (this changes the text boxes' outline too for some reason). Any critique you can offer would be great. Code:
Sub ChangeMultipleLineColors()
Dim sld As Slide, shp As Shape, PurpleColor(1) As Long, WhiteColor(1) As Long, BlackColor(1) As Long, BlueColor(1) As Long, Arr As Byte
Dim CheckColor As Long
'Set GrayColors
PurpleColor(1) = 16711807
WhiteColor(1) = 16777215
BlackColor(1) = 0
BlueColor(1) = 12611584
For Each sld In ActivePresentation.Slides
sld.Select 'not necessary but fun to watch
Debug.Print sld.SlideIndex 'again not necessary but useful if errors
For Each shp In sld.Shapes
If shp.Type <> msoGroup Then
shp.Select 'not necessary but fun to watch
CheckColor = shp.Line.ForeColor.RGB
If PurpleColor(1) = CheckColor Then
shp.Line.ForeColor.RGB = BlueColor(1) 'Purple to Blue
shp.Line.Weight = 1.5
If WhiteColor(1) = CheckColor Then
shp.Line.ForeColor.RGB = BlackColor(1) 'White to Black
shp.Line.Weight = 3 'Change Line Weight
End If
End If
End If
Next shp
Next sld
MsgBox "All Done Richard! Have a good day."
End Sub
Also, I have been trying to write a code which will just select all of the blue lines so I can animate these but for some reason it keeps selecting one black, dashed line. Code:
Sub SelectBlueLines()
Dim sld As Slide, shp As Shape, GrayColor(1 To 2) As Long, Arr As Byte
Dim CheckColor As Long
'Set GrayColors
GrayColor(1) = 12611584
'White 16777215
'Blue 12611584
'Black 0
For Each sld In ActivePresentation.Slides
sld.Select 'not necessary but fun to watch
Debug.Print sld.SlideIndex 'again not necessary but useful if errors
For Each shp In sld.Shapes
If shp.Type <> msoGroup Then
shp.Select 'not necessary but fun to watch
CheckColor = shp.Line.ForeColor.RGB
If GrayColor(1) = CheckColor Then
shp.Select
End If
End If
Next shp
Next sld
MsgBox "All Done Richard! Have a good day."
End Sub
Thanks again for your help! |
|
#9
|
|||
|
|||
|
The PPT file attached here.
|
|
#10
|
|||
|
|||
|
Some comments
In the first code your End If are not correctly placed. After checking for Purple the code will jump past the check for White which will never take place. Try this instead Code:
ub ChangeMultipleLineColors()
Dim sld As Slide, shp As Shape, PurpleColor As Long, WhiteColor As Long, BlackColor As Long, BlueColor As Long, Arr As Byte
Dim CheckColor As Long
'Set Colors
'These are not arrays so forget the (1)
PurpleColor = 16711807
WhiteColor = 16777215
BlackColor = 0
BlueColor = 12611584
For Each sld In ActivePresentation.Slides
'sld.Select 'not necessary and not a good idea
Debug.Print sld.SlideIndex 'again not necessary but useful if errors
For Each shp In sld.Shapes
If shp.Type <> msoGroup Then
'shp.Select 'not necessary as above
CheckColor = shp.Line.ForeColor.RGB
Select Case CheckColor
Case Is = PurpleColor
shp.Line.ForeColor.RGB = BlueColor 'Purple to Blue
shp.Line.Weight = 1.5
Case Is = WhiteColor
shp.Line.ForeColor.RGB = BlackColor 'White to Black
shp.Line.Weight = 3 'Change Line Weight
End Select
End If
Next shp
Next sld
MsgBox "All Done Richard! Have a good day."
End Sub
Code:
Sub SelectBlueLines()
Dim sld As Slide, shp As Shape
' this selcts the purple lines in the sample
' you cannot select shapes on multiple slides
' so choose just one
Set sld = ActivePresentation.Slides(1)
' unselect anything already selected
ActiveWindow.Selection.Unselect
Debug.Print sld.SlideIndex 'again not necessary but useful if errors
For Each shp In sld.Shapes
If shp.Type = msoLine Then
' When you select the default behaviour is to deselect anything already selected
' You will end up the last selection only UNLESS
' you specify "Do not replace"
If shp.Line.ForeColor = RGB(127, 0, 255) Then shp.Select Replace:=msoFalse
End If
Next shp
MsgBox "All Done Richard! Have a good day."
End Sub
Last edited by JohnWilson; 09-09-2014 at 12:18 AM. |
|
#11
|
|||
|
|||
|
Okay, I think I'm getting a handle on most of it now.
Can you recommend the best source of information about VBA coding to help me become more competent with it? Thank you again. |
|
#12
|
|||
|
|||
|
Your off to a great start. I first started learning VBA by asking John Wilson for some code snippets. He always delivers and writes very clean code. I studied it and not everything made sense at first. I started to learn programming concepts and then it started to click immediately. I have a website that teaches beginning VBA and programming but I dont like to be a self advertiser so you would need to PM me if you wanted that info. Lots of youtube videos out there that teach VBA but the one thing I can tell you. No matter where you go to try and learn VBA if the programming itself dosnt make sense it will be a doable but painful process. I speak from experience.
|
|
#13
|
|||
|
|||
|
A few people who program for major companies also publish code snippets. Studying these is a great way to learn.
Before you do this I would spend a day or so just learning some good habits it will pay off later. e.g. Why you should always declare variables (even though vba works without) Why you should use the correct type of variable (again even though vba is very forgiving about this) Why a naming convention for variables is a great idea. Some good places to study code Our site Steve Rindsberg's PPTFAQ Shyam Pillai (usually more complex stuff) There are more but there's lots to study there |
|
| Tags |
| lines, multiple, select |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
Way to find comments quickly
|
ep2002 | Word | 2 | 12-18-2013 02:03 AM |
| Quickly add file path name to footer | nimblewit | Word | 2 | 05-03-2013 05:17 AM |
Is there a function to easily and quickly highlight?
|
Verbum | Word | 3 | 02-05-2013 10:09 AM |
How do I Insert Acrobat PDF pages into Word Canvases quickly?
|
hemi_fan | Word | 1 | 04-12-2012 08:07 PM |
| finding contacts quickly | Jackdeanperry | Outlook | 0 | 12-21-2009 11:28 AM |