Ziggy54354 Posted August 6, 2008 Posted August 6, 2008 Is there a way to have a macro do a find and replace of code that is in a project? I'm changing the names of a bunch of bookmarks and I would like to automatically change the names of the bookmarks in the code to what I am changing them to. Does anyone know if this is possible? Share this post Link to post Share on other sites More sharing options...
ARandomOWL Posted August 6, 2008 Posted August 6, 2008 What program are u using? Doesn't it have a find & replace function? Share this post Link to post Share on other sites More sharing options...
Propane Posted August 7, 2008 Posted August 7, 2008 Find and replace / refactoring tools... example as how it would be done in my favorite editor vim: :%s/old_text/new_text/gc That will replace all old_text (can be a regex) to new_text, and every occurrence it finds will prompt you if you want the change to be made... pressing y will change it, pressing n will move on. Share this post Link to post Share on other sites More sharing options...
Waco Posted August 7, 2008 Posted August 7, 2008 It totally depends on what you are using. I can't think of many editors that don't have a Find/Replace prompt or command though... Share this post Link to post Share on other sites More sharing options...
Nemo Posted August 7, 2008 Posted August 7, 2008 Since you're working with VBA, then the easiest way would be to just use the built-in editor to do a find and replace. You can do a replace all if you're confident you know you won't accidental change something that you shouldn't. If you hit Ctl+H while in your project, you can specify to original text and replacement text, tell it where to search - current procedure, current project, etc., specify Match Case and Whole Word and then hit replace all. If you have some abnormally large number of changes to make, you could write code to parse the code, but a manual search and replace would probably be done before you could write and test the code. But, just for grins and giggles, you can export the code containing your macros to a text file - there's an export function under the File option on the menu bar. It'll have a .bas file extension, but is really a plain text file you can look at using any text editor like Notepad. You could then write VBA code to open the .bas file as a File System Object and parse the text to do a find and replace. Once you're done, you can import the file back into your project. Not too hard to do, but a lot more trouble than it's worth if you ask me. Share this post Link to post Share on other sites More sharing options...
Ziggy54354 Posted August 7, 2008 Posted August 7, 2008 I was trying to avoid find and replace as that would be manual and i would have to do thousands of these but I found a perfect solution. Check out the following if you guys are interested. http://pubs.logicalexpressions.com/pub0009...icle.asp?ID=307 and http://www.cpearson.com/excel/vbe.aspx Share this post Link to post Share on other sites More sharing options...
Recommended Posts
Please sign in to comment
You will be able to leave a comment after signing in
Sign In Now