Are There Any macros that can substitute one block of code for another, in multiple webpages

Posted on 2010-11-14
Last Modified: 2012-08-13
I need to make the same code change to approximately 75 webpages. There are 2 changes I need to make to each page. Although different, each change involves a "replace this block of code" with a different block of code.

Before hiring a subcontractor to manually do this, I'm wondering if there is any macro software available that can accomplish this? It would need to be fairly simple to set up because, except for a few isolated HTML commands, I really don't know how to program.

I know that there are numerous free as well as commercial macro software programs out there, but I have never used any.

Thanks for your help.
Question by:photoman11
  • 4
  • 4
LVL 44

Accepted Solution

scrathcyboy earned 425 total points
ID: 34133144
Can you identify the code block to be replaced by a unique starting tag or word and a unique ending?

And is the code to be replaced available in a separate file?  Does each HTML file get the same code replacement.  IF you can be a bit more specific, we can narrow it down.
LVL 10

Assisted Solution

by:Tyler Laczko
Tyler Laczko earned 75 total points
ID: 34138250
You can use wordpad, its built into windows, and do a find / replace for the code.

Author Comment

ID: 34138709

I have attached the HTML file of a representative page. The page is visible at

If you open up the file in an editor, the first block of comments which explains what I want deleted and added, is at line #124. The 2nd block of code is at line #293.

The same code to be replaced is on every page, although not at the same line number as in this page. The blocks of code used as the replacement code, is identical for all pages also.


Thank you. Find and replace would certainly work, but still require a lot of manual intervention. What am hoping to find is some way to automate the process to avoid the manual work.
LVL 44

Expert Comment

ID: 34138871
I looked at the code, and no, I don't see any easy or safe way to automate the 2 replacements -- any macro would depend on your HTML editor, and if you missed one tag, it would foul up all the pages very nicely for you.  Drop me an email if you want help.

I did see one problem though, which you might want to field before you do these replacements.  The INCLUDE file is a SHTML, and I think you will have trouble including a secure HTML page in a non-Secure HTML page.  Does the extension have to be SHTML?  As I recall, both the web server and most browsers will choke on this type of cross-security include.
Comprehensive Backup Solutions for Microsoft

Acronis protects the complete Microsoft technology stack: Windows Server, Windows PC, laptop and Surface data; Microsoft business applications; Microsoft Hyper-V; Azure VMs; Microsoft Windows Server 2016; Microsoft Exchange 2016 and SQL Server 2016.


Author Comment

ID: 34142387

Thanks. No problem about the SHTML include - it is my hosting service that insists upon this approach.

Confused about comments that macro seems dangerous, but to drop you an email if want help. Help in a way other than we're discussing?? Please explain.
LVL 44

Expert Comment

ID: 34147731
For a macro to work, you have to have a start point and an end point of specific text (or in the case of HTML, code).  Now if that end-point code is missing in a page, or duplicated within the macro area to be replaced, then only part of it will be replaced -- and possibly in all your documents.  Now you have a mess because the code was not completely replaced, so you spend more time fixing it than you would have doing it by hand in the first place.

Author Comment

ID: 34151452
Got it. Thank you.

By the way, do you recommend any macros for things in general, which do not require heavy programming abilities?
LVL 44

Expert Comment

ID: 34151928
Macros depend on the software you are using.  MS Word continued the tradition of Wordperfect to provide recordable macros for repeated steps in editing word documents.  Making them takes a bit of practice, they are intimidating at first.  But they can be real time savers.

The question of "parsing HTML" code has cropped up here repeatedly on EE, and it is far more fearsome than editing a document.  Browsers are often forgiving -- if you forget to end a form or table with the closing tag, they will render the form or table anyway.  

But in PARSING the HTML -- i.e. going through it and blocking out all the code that exists in a FORM, for example -- if the person put the closing </FORM> tag, then everything is OK.  What happens if they forgot it?  Then instead of parsing the HTML to remove the FORM only, you end up deleting the entire document after the start of the FORM tag, because no end tag was ever found.

That is probably why I have never seen a program to go through HTML code (i.e. parse it) and cut out whole blocks of code and replace with other blocks of code.  You can get macros to change case or search just in a single tag, but the risk of balancing all tags is too great for mass search replace.

So when you do a google search for this -- macro to search replace HTML
almost all you get is discussions of WORD macros and EXCEL macros !!!

But neither Word nor Excel are HTML editors.  Therefore you have to find an HTML editor that has macro capability on the HTML code itself (not the finished page) to correctly search and replace the code, and neither do it.  Check your own HTML editor to see if it has Macro features.  IF so, try them.


Author Comment

ID: 34152491
thanks for your advice.

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Microsoft  Partnership 1 70
HTML code not showing slider block in Magento 2 30
Form Submit falis 6 27
How to get this page layout correct 13 9
Healthcare organizations in the United States must adhere to the guidance of both the HIPAA (Health Insurance Portability and Accountability Act) and HITECH (Health Information Technology for Economic and Clinical Health Act) for securing and protec…
Is your Office 365 signature not working the way you want it to? Are signature updates taking up too much of your time? Let's run through the most common problems that an IT administrator can encounter when dealing with Office 365 email signatures.
The viewer will learn how to successfully download and install the SARDU utility on Windows 8, without downloading adware.
XMind Plus helps organize all details/aspects of any project from large to small in an orderly and concise manner. If you are working on a complex project, use this micro tutorial to show you how to make a basic flow chart. The software is free when…

863 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now