Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Here is the jist of it. No, I have not debugged this, that is an excercise for the reader. And, this is done off the top of my head. (Except the File commenter...That's a real Macro that I use).</p> <pre><code>function CommentAllFiles option explicit Dim ActiveProjectFullName Dim dte80 As EnvDTE80.Solution2 ActiveProjectFullName = dte80.Projects.Item(0).FullName If ActiveProjectFullName = "" Then MsgBox("No project loaded!") Exit Sub End If Err.Number = 0 doc.Open(ActiveProjectFullName, "Text", True) If Err.Number &lt;&gt; 0 Then MsgBox("Open " + ActiveProjectFullName + " failed: " &amp; Hex(Err.Number)) Exit Sub End If ActiveDocument.Goto(1, 1, vsMovementOptions.vsMovementOptionsMove) ' Build search string Dim SearchString Dim vsFindOptionsValue As Integer SearchString = "^SOURCE=.*" + dn + "$" while ActiveDocument.Selection.FindText(SearchString, vsFindOptions.vsFindOptionsFromStart + vsFindOptions.vsFindOptionsRegularExpression) Dim TheFile TheFile = ActiveDocument.Selection.Text TheFile = Mid(TheFile, 8) doc.Open(TheFile) wend ActiveDocument.Close() end function </code></pre> <p>Tried and true "Flower Box" adder:</p> <pre><code> Function IsClassDef() Dim ColNum Dim LineNum Dim sText sText = ActiveDocument.Selection.ToString() If sText = "" Then 'ActiveDocument.Selection.WordRight(dsExtend) 'sText = ActiveDocument.Selection 'sText = ucase(trim(sText)) End If If (sText = "CLASS") Then IsClassDef = True Else IsClassDef = False End If End Function Sub AddCommentBlock() 'DESCRIPTION: Add Commecnt block to header, CPP files and Class Defs AddCPPFileDesc() End Sub Sub AddCPPFileDesc() 'DESCRIPTION: Add File desc block to the top of a CPP file Dim selection As EnvDTE.TextSelection ActiveDocument.Selection.StartOfLine() Dim editPoint As EnvDTE.EditPoint selection = DTE.ActiveDocument.Selection() editPoint = selection.TopPoint.CreateEditPoint() Dim bOk, sExt, IsCpp, IsHdr, sHeader, IsCSharp bOk = True IsCpp = False IsCSharp = False If ActiveDocument.Selection.CurrentLine &gt; 10 Then If MsgBox("You are not at the top of the file. Are you sure you want to continue?", vbYesNo + vbDefaultButton2) = vbNo Then bOk = False End If End If If (bOk) Then sExt = ucase(right(ActiveDocument.Name, 4)) IsCpp = sExt = ".CPP" IsHdr = Right(sExt, 2) = ".H" IsCSharp = sExt = ".CS" If (IsCpp) Then sHeader = left(ActiveDocument.Name, len(ActiveDocument.Name) - 3) + "h" FileDescTopBlock(1) editPoint.Insert("#include " + Chr(34) + "StdAfx.h" + Chr(34) + vbLf) editPoint.Insert("#include " + Chr(34) + sHeader + Chr(34) + vbLf) ElseIf (IsCSharp) Then FileDescTopBlock(1) Else If IsHdr Then 'If IsCLassDef() Then 'AddClassDef() 'Else AddHeaderFileDesc() 'End If Else FileDescTopBlock(1) End If End If End If End Sub Sub AddHeaderFileDesc() FileDescTopBlock(0) Dim selection As EnvDTE.TextSelection ActiveDocument.Selection.StartOfLine() Dim editPoint As EnvDTE.EditPoint selection = DTE.ActiveDocument.Selection() editPoint = selection.TopPoint.CreateEditPoint() editPoint.Insert("#pragma once" + vbLf) End Sub Sub FileDescTopBlock(ByVal HasRevHistory) 'DESCRIPTION: Add File desc block to the top of a CPP file Dim selection As EnvDTE.TextSelection ActiveDocument.Selection.StartOfLine() ActiveDocument.Selection.EndOfLine() Dim sComment sComment = ActiveDocument.Selection.ToString() If Left(sComment, 2) = "//" Then ActiveDocument.Selection.Delete() sComment = LTrim(Mid(sComment, 3)) Else sComment = "" End If Dim sLineBreak Dim sFileName Dim sBlock sLineBreak = "////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////" sFileName = ActiveDocument.Name ActiveDocument.Selection.StartOfDocument() sBlock = sLineBreak &amp; vbLf &amp; _ "// File : " &amp; sFileName &amp; vbLf &amp; _ "// Author : Larry Frieson" &amp; vbLf &amp; _ "// Desc : " &amp; sComment &amp; vbLf &amp; _ "// Date : " &amp; CStr(Now.Date()) &amp; vbLf &amp; _ "//" &amp; vbLf &amp; _ "// Copyright © 20" + Right(CStr(Now.Year.ToString()), 2) + " MLinks Technologies. All rights reserved" + vbLf If (HasRevHistory &gt; 0) Then sBlock = sBlock &amp; _ "//" &amp; vbLf &amp; _ "// Revision History: " &amp; vbLf &amp; _ "// " &amp; CStr(Now) &amp; " created." &amp; vbLf &amp; _ "// " &amp; vbLf End If sBlock = sBlock + sLineBreak + vbLf Dim editPoint As EnvDTE.EditPoint selection = DTE.ActiveDocument.Selection() editPoint = selection.TopPoint.CreateEditPoint() editPoint.Insert(sBlock) End Sub </code></pre> <p>Hope this helps, or at least gives you some ideas. Again, I didn't test/debug the "source file looper", I figure you can handle that.</p> <p>Larry</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload