25854

Can I have a macro run whenever I save a file in Visual Studio 2005?

When I save a file in Visual Studio 2005, I'd like to have a macro also run that updates a copyright (through a regular expression search and replace).

I'm not new to regular expressions, but I am new to VB/VBA and Visual Studio macros, so what I need help with specifically is:

<ol> <li>

getting a macro to run upon save, preferably after I press CTRL-S but before it actually writes the file so that the results of the search and replace are actually saved without having to save twice

</li> <li>

calling search and replace for a regular expression from inside the VB/VBA macro

</li> </ol>

Answer1:

You can record, rename, and assign a macro. Here's what I did.

<ol> <li>Menu: /Tools/Macros/Record Temporary Macro</li> <li>Ctrl</kbd>-Shift</kbd>-H</kbd> - brings up the solution wide search and replace</li> <li>Under find options in this dialog select regular expressions. Note these will be slightly different in syntax than what you find in System.Text.RegularExpressions.</li> <li>Alt</kbd> then F</kbd> then L</kbd> - file save all</li> <li>Open the macro editor with Menu: /tools/macros/macro explorer</li> <li>Right click the temporary macro to edit. </li> <li>In the Project Explorer of this macro right click to rename the temporary macro and save</li> <li>Assign to a key combination: Here’s a link to assign it to a key combination </li> </ol>

So the idea is you can record something that is almost what you want. Then tweak it, and assign it to a key combination. Definitely try your regex first and note that there will be a dialog interrupting you if anything in your solution is read-only.

Recommend

  • MySQL performance, inner join, how to avoid Using temporary and filesort
  • Scanf Validation
  • What is the preferred way to compose a set from multiple lists in Python
  • scons: How to deal with dynamic targets?
  • Scroll down whole browser window
  • How can I pass the index of a for loop as the argument for pthread_create
  • time_t conversion format question
  • Noise after changing volume in QAudioOutput
  • Can TextIO write to prefixes derived from the window maxTimestamp?
  • inserting duplicate records with SQL
  • How to tell if the sdcard is mounted in Android?
  • Creating Setup of large data with NSIS Script
  • Replicating and differentiating portions of a form
  • Can't find cygwin setup.exe file?
  • HTML code to upload images
  • How to give custom name to Sqoop output files
  • NSMutableArray Access Issue
  • Nodejs bluebird promise fails while processing image
  • PHPStorm Namespace support not working for Symfony2 projects
  • Reassigning an array frees the memory used by it?
  • Converter from SAT to 3-SAT
  • What does “t” refer to in this SQL?
  • Trying to get the char code of ENTER key
  • Clarification on min distance on LocationManager.requestLocationUpdates method, min Distance paramet
  • Is playing sound in Javascript performance heavy?
  • How can the INSERT … ON CONFLICT (id) DO UPDATE… syntax be used with a sequence ID?
  • Marklogic : Query response time is very high
  • Installing Apache MyFaces 2 on WildFly 8.2.0
  • How to know when stdin is empty if it contains EOF?
  • Why querying a date BC is changed to AD in Java?
  • Record samples being played with OpenAL
  • Java: can you cast Class into a specific interface?
  • Why value captured by reference in lambda is broken? [duplicate]
  • Insert into database using onclick function
  • Fetching methods from BroadcastReceiver to update UI
  • ILMerge & Keep Assembly Name
  • Knitr HTML Loop - Some HTML output, some R output
  • Can a Chrome extension content script make an jQuery AJAX request for an html file that is itself a
  • ExecuteAsync RestSharp to allow backgroundWorker CancellationPending c#
  • How do I use LINQ to get all the Items that have a particular SubItem?