代码格式化脚本CodeFormat2010-01-09没学过VBSript,但为了格式化自己要用的代码,找来找去没找到合适的,勉强作了一个。用法:将下面代码存成一个“.DSM”后缀的文件,用VC6装载这个宏,打开任一C,C++代码文件,运行宏,代码将按系统设置的方式(空格或TAB)得到格式化。由于不懂VBSript,做得不完善,问题是:1:必须把欲格式化的文件在VC等环境下打开,不能按目录自动检索该格式化的文件;2:在“{”后有字符时{}里面的失去缩进;条件:文件必须可写。存在的价值:VC环境是大家信任的环境,绝不会因为它对代码格式化而使代码不能编译。希望有人不吝技术,把它做好一点。如果有新版,请寄给我一份:Yanggr@cbcyber.comSub FormatByCode() Dim myDocument For Each myDocument in Application.Documents myDocument.Active = True myDocument.Selection.SelectAll Dim EndLine, CurrLine EndLine=myDocument.Selection.BottomLine myDocument.Selection.StartOfLine CurrLine=myDocument.Selection.CurrentLine while ( CurrLine<=EndLine ) myDocument.Selection.SelectLine myDocument.Selection = LTrim(myDocument.Selection) CurrLine=myDocument.Selection.CurrentLine wend myDocument.Selection.SelectAll myDocument.Selection.Unindent myDocument.Selection.Unindent myDocument.Selection.Unindent myDocument.Selection.Unindent myDocument.Selection.Unindent myDocument.Selection.Unindent myDocument.Selection.SmartFormat myDocument.Save myDocument.Close dsSaveChangesPrompt Next End Sub