Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 12-22-2021, 09:44 PM
Bikram Bikram is offline Replacing_Colors_Of_Document Windows 10 Replacing_Colors_Of_Document Office 2007
Advanced Beginner
Replacing_Colors_Of_Document
 
Join Date: Jul 2021
Location: Nepal
Posts: 94
Bikram is on a distinguished road
Default Replacing_Colors_Of_Document

Greetings to all,
I have documents that are in cyan color and it needs to be changed into magenta. Is there any way that I can achieve the desired result with the least effort?



I have tried some macros from different websites to find and replace colors but failed to get the job done.

I want to change the values of cyan to magenta for example
10% cyan to 10% magenta
100% cyan to 100% magenta
and so on.

I have attached a sample doc. Plz have a look and suggest the solution or best possible alternatives. Thanks in advance
Attached Files
File Type: doc Sample.doc (74.5 KB, 18 views)
Reply With Quote
  #2  
Old 12-25-2021, 11:12 AM
Peterson Peterson is offline Replacing_Colors_Of_Document Windows 10 Replacing_Colors_Of_Document Office 2019
Competent Performer
 
Join Date: Jan 2017
Posts: 143
Peterson is on a distinguished road
Default

The colors in your sample document do not match the values in your message; that is, the cyans in the document are not precisely 10% and 100%.

Do you mean to say that the precise cyan values in your document---whatever they may be---need to be changed to precisely 10% and 100% magenta?
Reply With Quote
  #3  
Old 12-25-2021, 01:50 PM
Guessed's Avatar
Guessed Guessed is offline Replacing_Colors_Of_Document Windows 10 Replacing_Colors_Of_Document Office 2016
Expert
 
Join Date: Mar 2010
Location: Canberra/Melbourne Australia
Posts: 4,158
Guessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant future
Default

Word doesn't work with CMYK colours so Cyan is not simply interchangeable with Magenta.

Word's colours are RGB-based so each 'cyan' colour is going to be held in Word as a combination of RGB and hence need specific matching pairs to convert 100% cyan to its rgb equivalent to use in the find and then replace it with the target rgb value.

The solid cyan in your doc has RGB values of 0,174,239. The paler cyan is 225,244,253.
__________________
Andrew Lockton
Chrysalis Design, Melbourne Australia
Reply With Quote
  #4  
Old 12-26-2021, 01:04 AM
Bikram Bikram is offline Replacing_Colors_Of_Document Windows 10 Replacing_Colors_Of_Document Office 2007
Advanced Beginner
Replacing_Colors_Of_Document
 
Join Date: Jul 2021
Location: Nepal
Posts: 94
Bikram is on a distinguished road
Default

Thank you Andrew and Peterson for the replies. Yeah! word doesn't work with CMYK. So, I changed 100% cyan value to RGB which corresponds to 0,174,239, and I have done the same for the 10% cyan value i.e. RGB 255,244,253. I should have used Indesign instead but I prefer working with the msword as it is more convenient and comfortable to work for me. Now, what I want to do is find those two values in the document and change RGB 0,174,239 to RGB 236,0,140 and RBG 255,244,253 to RGB 253,233,241. But they are used in various places such as for shading, borders, text boxes.
Code:
Sub Colorsquiz()
  Dim i As Long
  Dim Rng As Range
  Dim Para As Paragraph
   
  Set Rng = ActiveDocument.Range
  
  Const col1 As Long = RGB(0, 174, 239)
  Const col2 As Long = RGB(255, 244, 253)
  
  

    For i = 1 To Rng.Paragraphs.Count
        Set Para = Rng.Paragraphs(i)
            Para.Range.Select
        Select Case Para.Range.ParagraphFormat.Shading.BackgroundPatternColor
            Case col1
                Para.Range.ParagraphFormat.Shading.BackgroundPatternColor = RGB(236, 0, 140)
            Case col2
                Para.Range.ParagraphFormat.Shading.BackgroundPatternColor = RGB(253, 233, 241)
     
        End Select
     
     ' For Font
        Select Case Para.Range.Font.Color
            Case "(0,174,239)"
                Para.Range.Font.Color = RGB(236, 0, 140)
        End Select
       
    Next i
  
  
End Sub
I tried to implement the above code but It doesn't work. It was for the shading and font. But I also need to change the colors of shapes. How can I achieve the desired result?
Reply With Quote
  #5  
Old 12-26-2021, 04:25 AM
rollis13's Avatar
rollis13 rollis13 is offline Replacing_Colors_Of_Document Windows 10 Replacing_Colors_Of_Document Office 2016
Competent Performer
 
Join Date: Jan 2021
Location: Cordenons
Posts: 142
rollis13 will become famous soon enough
Default

Hi to all.
With these modifications you will go a step ahead:
Code:
Option Explicit
Sub Colorsquiz()
    Dim i      As Long
    Dim Rng    As Range
    Dim Para   As Paragraph
    Set Rng = ActiveDocument.Range
    For i = 1 To Rng.Paragraphs.Count
        Set Para = Rng.Paragraphs(i)
        Para.Range.Select
        Select Case Para.Range.ParagraphFormat.Shading.BackgroundPatternColor
            Case RGB(0, 174, 239)
                Para.Range.ParagraphFormat.Shading.BackgroundPatternColor = RGB(236, 0, 140)
            Case RGB(255, 244, 253)
                Para.Range.ParagraphFormat.Shading.BackgroundPatternColor = RGB(253, 233, 241)
        End Select
        'For Font
        If Para.Range.Font.Color = RGB(0, 174, 239) Then Para.Range.Font.Color = RGB(236, 0, 140)
    Next i
End Sub
Reply With Quote
  #6  
Old 12-26-2021, 04:30 AM
Bikram Bikram is offline Replacing_Colors_Of_Document Windows 10 Replacing_Colors_Of_Document Office 2007
Advanced Beginner
Replacing_Colors_Of_Document
 
Join Date: Jul 2021
Location: Nepal
Posts: 94
Bikram is on a distinguished road
Default

Thank you, rollis.
Reply With Quote
  #7  
Old 12-27-2021, 01:38 PM
Guessed's Avatar
Guessed Guessed is offline Replacing_Colors_Of_Document Windows 10 Replacing_Colors_Of_Document Office 2016
Expert
 
Join Date: Mar 2010
Location: Canberra/Melbourne Australia
Posts: 4,158
Guessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant future
Default

I tried a different approach of saving the doc as docx and then doing a search and replace in the xml files of document.xml and styles.xml.

In the XML the cyan colours were 00AEFF and E1F4FD.
I changed these to 990099 and FFBDFF respectively

This approach replaced everything except two elements - perhaps because they weren't exactly the same colour.
__________________
Andrew Lockton
Chrysalis Design, Melbourne Australia
Reply With Quote
  #8  
Old 12-27-2021, 09:31 PM
Bikram Bikram is offline Replacing_Colors_Of_Document Windows 10 Replacing_Colors_Of_Document Office 2007
Advanced Beginner
Replacing_Colors_Of_Document
 
Join Date: Jul 2021
Location: Nepal
Posts: 94
Bikram is on a distinguished road
Default

Thank you Andrew for the reply. I found it quite confusing because i don't know much about xml files. Can you please guide me stepwise on how can I achieve the result you achieved? It would be of great help.
Reply With Quote
  #9  
Old 12-28-2021, 05:48 PM
Guessed's Avatar
Guessed Guessed is offline Replacing_Colors_Of_Document Windows 10 Replacing_Colors_Of_Document Office 2016
Expert
 
Join Date: Mar 2010
Location: Canberra/Melbourne Australia
Posts: 4,158
Guessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant future
Default

OK, first steps are:
1. Install 7zip and Notepad++ which you can find online.
2. Open the .doc file in Word and do a SaveAs to change its format to .docx. Doc file format is very old and won't work with this method.
3. Make sure Notepad++ is set as your default application to edit .xml files. Do this by creating a text file on your machine and changing its file extension to .xml. If double clicking it opens it in Notepad++ then you are good to go. If not, right click on the file and choose Open with... to select Notepad++. Make sure you check the box that says "Always use this app to open..."

I'll post the rest of the instructions later.
__________________
Andrew Lockton
Chrysalis Design, Melbourne Australia
Reply With Quote
  #10  
Old 12-28-2021, 09:33 PM
Bikram Bikram is offline Replacing_Colors_Of_Document Windows 10 Replacing_Colors_Of_Document Office 2007
Advanced Beginner
Replacing_Colors_Of_Document
 
Join Date: Jul 2021
Location: Nepal
Posts: 94
Bikram is on a distinguished road
Default

All set boss!! Waiting for part II
Reply With Quote
  #11  
Old 12-29-2021, 01:08 PM
Guessed's Avatar
Guessed Guessed is offline Replacing_Colors_Of_Document Windows 10 Replacing_Colors_Of_Document Office 2016
Expert
 
Join Date: Mar 2010
Location: Canberra/Melbourne Australia
Posts: 4,158
Guessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant future
Default

Part II

First the disclaimer - When editing a Word document with this method, you should always do it on a copy of the file. It is possible that you might make a change to the file structure which stops Word from being able to open the contents. If this is the case you can always revert to the original version.

1. In Windows Explorer, right click on the docx version of the file and choose 7zip>Open Archive.
This will open a window revealing that the docx file is actually a zipped file containing folders and files.
2. Navigate inside the folder called word. Click on document.xml and then Ctrl-click on styles.xml to select them both and then Right-click on one of them and choose Open
This should open both files in Notepad++. Have a look at the contents of the document.xml file and you will notice the occasional tag w:color which shows that the colors in the file are in Hex format
3. Under the Search menu, choose Replace... In the find what box type the hex code of the color you want to find (00AEFF) and in the replace with box put in the code you want to change it to (990099). Click the button that says Replace All in all opened documents
4. Do the same for the paler cyan color codes
5. Click the Save All button on the toolbar (4th one from left) and then click the Close All button (6th one from left). Then close Notepad++
6. As you return to 7zip, you should be prompted to update the archive - choose OK and then close 7zip.

Now you should be able to double click the docx file to open it in Word and have a look at the result. If you notice any remaining colours this method didn't replace, make a note of its hex value and repeat the process. In the case of the document you posted earlier in this thread, there is a cyan background on the text "Concept Review" with a different hex code. You can find out what its hex code is by noting that the shading comes from the style Bb1 which you can modify and going to Format > Border... > Shading > Select the fill > More Colors... Then make note of the hex code which says it is #44C8F5
This is your clue that your earlier search and replace should have also included this code (without the # symbol)
__________________
Andrew Lockton
Chrysalis Design, Melbourne Australia
Reply With Quote
  #12  
Old 12-29-2021, 09:38 PM
Bikram Bikram is offline Replacing_Colors_Of_Document Windows 10 Replacing_Colors_Of_Document Office 2007
Advanced Beginner
Replacing_Colors_Of_Document
 
Join Date: Jul 2021
Location: Nepal
Posts: 94
Bikram is on a distinguished road
Default

Thank you, Andrew. It did a great Job.
Reply With Quote
Reply



Other Forums: Access Forums

All times are GMT -7. The time now is 03:39 PM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2025, vBulletin Solutions Inc.
Search Engine Optimisation provided by DragonByte SEO (Lite) - vBulletin Mods & Addons Copyright © 2025 DragonByte Technologies Ltd.
MSOfficeForums.com is not affiliated with Microsoft