#1
|
|||
|
|||
Quickly select lines of certain colour
Hi all,
I have a large number of slides with different colour lines and want to change the colour of all the grey lines to blue. The colours would have been applied individually separate to any themes. I was thinking about using macros but I don't know enough about them to carry out the operation. I have researched this online but to no avail, any help you can offer me is greatly appreciated. Kind Regards, Richard |
#2
|
|||
|
|||
If you could post a sample presentation that has the gray lines and the desired blue line result I could write you a code that would take care of it for you in a couple of seconds.
|
#3
|
|||
|
|||
Are all the lines EXACTLY the same gray?
Do you mean lines as in connecters or lines as in shape borders? |
#4
|
|||
|
|||
Hi, thanks for the responses. I have attached one of the slides to this post.
The lines would have been originally drawn in AutoCAD, saved as a metafile and then imported into PowerPoint with colour applied individually within PowerPoint. I would love if you can show me how to write the code as I will no doubt have the same problem with other slides very soon. Thank you. |
#5
|
|||
|
|||
I would be happy to help you learn basically the program would be a loop that looks at every slide and every shape on it. If a shape meets the criteria (the line is a gray) then the code would turn it blue and move on to the next shape.
The gray appears to be a line forecolor of 10921638 while the blue is a forecolor of 16711680 Now a couple things I basically already wrote the code that will do this however since you want to learn we need to go over it at your speed. You mentioned you dont know enough about macros so do you have any VBA experience or programming experience in general? its ok if you dont we just need to know where to start. and to John Wilson the most amazing PPT programmer I have ever come in contact with. If I am treading on your territory please let me know and I can back off. I respect you so much. |
#6
|
|||
|
|||
I have very limited experience with VBA. I use basic macros now and then but never have edited the code/text within VBA. I have messed around with .html code on a website before, nothing major, just editing font really.
|
#7
|
|||
|
|||
Go for Excelled I am pretty busy with a large US Law firm right now.
|
#8
|
|||
|
|||
Quote:
I will try to make you proud |
#9
|
|||
|
|||
Ok RFoudy,
Now that I have an idea of your experience level I will be more than happy to get you started with VBA coding. Now the big thing to understand is that this will be a process a lot of it will not make sense at first but you are just getting your feet wet. You mentioned that you have done some HTML editing. That's great it gives you the opportunity to see how changing code of any kind can produce a different result. so let's start with your project here. It is important to understand the logic of what you want the computer to do. You want code to look at all all sildes for each slide you want the code to look at all shapes. Determine if they are gray and then color them blue. After that we want the code to continue to the next shape then the next slide and repeat. Some keywords to think about here are: All, every, repeat etc. When these words are used in your plan you need what is called a loop. A loop will execute a block of code and then keep on going until you tell it when to stop. The other words used are: if If statements are used in nearly every programming language they tell the code to execute something IF it meets a condition. With that we now know that the code for this will consist of a loop that looks at all slides, in that loop we have another loop that looks at every shape on the slide. Within that loop an If statement that checks if the line is gray. OK sounds fun dosnt it? Lets start with setting up the code so Powerpoint knows what we want it to do. We will not go over every detail here but rather an introduction to the objects we are about to use. In the next post we will start with the code and I will explain it as I go. |
#10
|
|||
|
|||
Sorry about the the late reply but I did notice that not all of the gray lines are the same kind of gray. That poses a huge problem with writing a basic code. The first thing to do is to write a procedure that will tell us all of the line color numbers.
Follow along with the simple code that does nothing more than give us the line color for each shape on slide 1. This is a great way to see a loop work. Now everytime I go to explain something in the code I will use a ' This represents a comment in VBA. Comments are not code executed but rather a message to the programmer or anybody looking over the code. Here we go. Code:
Sub GetTheLineColors() 'This is the very first thing you write for every procedure. Sub 'Just tells VBA that you are writing a sub routine. 'The GetTheLineColors is just a name I came up with. You can use 'Whatever you want but it can contain most special characters 'and no spaces. The () will be written automatically for you as well 'as an End Sub Dim shp As Shape 'Here we use the Dim keyword that is used to DECLARE a variable. 'I will not go over variables in detail here just know that a variable 'Holds information so it can be used throughout the code. 'You can use almost whatever name for a variable you want. 'I used shp because it makes the most sense. and Shape is already taken 'because it is used in PPT VBA already just like I could not make a variable called 'ActivePresentation. For Each shp In ActivePresentation.Slides(1).Shapes 'There are several loops available. This one is called the for each 'It basically says that FOR this instance do something 'In this case it is going to go through each shape in the 'Active presentation's Slides and shapes 'Notice I put in Slides(1) This checks just the first slide. 'When we write the second code you will see how we change that and why. Debug.Print shp.Name & ";" & shp.Line.ForeColor.RGB 'Debug.print basically writes a string to the immediate window. 'in this case I have the shape name a ; and then the linecolor which 'is what we are after. I am separating the 2 with a ; so I can copy 'and paste the result into Excel and separate them into columns. Next shp 'For any loop you need to tell it to keep going. The For loop 'Uses the next statement which says "now that you are done with that 'code block move to the next shape and continue until EACH shape has been 'visited. 'Remember how I said End Sub would be written in. Here it is 'This tell VBA that the procedure is over End Sub Once I ran that code I copy and pasted the result into Excel and then I manually changed all of the "Gray" lines to a consistent green color. Then I ran the the same script again and compared how many Gray variations there are. Here are the results. 10921638 12287562 So there are 2 possibilities of Gray lines here. 2 is not that big of a deal since an IF statement could easily check 2 conditions but since you will want to be able to do this in the future you will be learning about arrays as well and we will need to put another loop into our next procedure but first you need to use the code above and try this yourself. It's important to understand how the loop works. What would be awesome is if you could use the loop to identify what line color of blue you are looking for. Post that and I will continue to write the code for the next part since it still needs something else. |
#11
|
|||
|
|||
By the way this is what that same code would like without all of the comments.
It does the very same thing Code:
Sub GetTheLineColors() Dim shp As Shape For Each shp In ActivePresentation.Slides(1).Shapes Debug.Print shp.Name & ";" & shp.Line.ForeColor.RGB Next shp End Sub |
#12
|
|||
|
|||
RFoudy,
I have the procedure written now and it works. However one thing that will make it more complex is if you have groups that need the line colors changed. It can certainly be done but I would need to debug it a little bit. Right now I have skipping over groups and it worked 100% for the sample you sent me. Let me know if this is not an issue and if it isnt I will post it with some explanations and you will be all set. EDIT I will post it now and if you want we can go over it Code:
Sub ChangeLineColor() Dim sld As Slide, shp As Shape, GrayColor(1 To 2) As Long, Arr As Byte Dim CheckColor As Long 'Set GrayColors GrayColor(1) = 10921638 GrayColor(2) = 12287562 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 For Arr = 1 To 2 If GrayColor(Arr) = CheckColor Then shp.Line.ForeColor.RGB = 12287562 'Change to blue End If Next Arr End If Next shp Next sld MsgBox "done" End Sub |
#13
|
|||
|
|||
I had to add a third gray to make it work for all lines
GrayColor(3) = 12566463 |
#14
|
|||
|
|||
Hi John,
Thanks for that catch I must have ran my GetTheLIneColors after I made a change to one of the gray lines and missed it. |
#15
|
|||
|
|||
Here is the new code with John Wilson's find
Code:
Sub ChangeLineColor() Dim sld As Slide, shp As Shape, GrayColor(1 To 3) As Long, Arr As Byte Dim CheckColor As Long 'Set GrayColors GrayColor(1) = 10921638 GrayColor(2) = 12287562 GrayColor(3) = 12566463 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 For Arr = 1 To 3 If GrayColor(Arr) = CheckColor Then shp.Line.ForeColor.RGB = 12287562 'Change to blue End If Next Arr End If Next shp Next sld MsgBox "done" End Sub |
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 |