Imports EnvDTE Imports System.Diagnostics Imports System.Runtime.InteropServices Public Module AddGuid Sub AddGuid() 'DTEドキュメントを取得する Dim DteDocument As EnvDTE.Document = Nothing Try DteDocument = DTE.ActiveDocument() 'Selectionオブジェクトを取得する Dim sel As TextSelection = Nothing Try sel = DteDocument.Selection() 'GUIDを取得する Dim guid As System.Guid = System.Guid.NewGuid() '文字列を書き出す sel.Text = """" + guid.ToString + """" Finally 'Selectionオブジェクトを開放する If (Not sel Is Nothing) Then Marshal.ReleaseComObject(sel) End If End Try Finally 'DTEドキュメントを開放する If (Not DteDocument Is Nothing) Then Marshal.ReleaseComObject(DteDocument) End If End Try End Sub End Module