作者未學過 VBScript,但為了格式化自用代碼,參考現有資源勉強撰寫了此巨集。其核心價值在於:在 VC6 這個受信任的開發環境中進行格式化,絕不會導致代碼無法編譯。
.DSM 副檔名的檔案。{ 後同行有字元,大括號內部程式碼會遺失縮排。Sub 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
作者誠摯希望有技術高手能完善此巨集(支援批次處理、修正縮排邏輯等),若有新版本請寄送至 Yanggr@cbcyber.com。