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.
Enterprise Mobility and BYOD For Dummies

Like “For Dummies” books, you can read this in whatever order you choose and learn about mobility and BYOD; and how to put a competitive mobile infrastructure in place. Developed for SMBs and large enterprises alike, you will find helpful use cases, planning, and implementation.

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.

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

Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
ASP:Radiobuttonlist/asp:RadioButtonListItem custom styling 1 40
Map software access 4 29
Else condition 9 15
ASP server side get value 15 18
In this article, you will read about the trends across the human resources departments for the upcoming year. Some of them include improving employee experience, adopting new technologies, using HR software to its full extent, and integrating artifi…
Developer portfolios can be a bit of an enigma—how do you present yourself to employers without burying them in lines of code?  A modern portfolio is more than just work samples, it’s also a statement of how you work.
The viewer will learn the benefit of using external CSS files and the relationship between class and ID selectors. Create your external css file by saving it as style.css then set up your style tags: (CODE) Reference the nav tag and set your prop…
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

813 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

16 Experts available now in Live!

Get 1:1 Help Now