' GotoRelatedSrc Macro ' ' Copyright (c) 1999 by Mike Woodring ' ' Released to the public domain for use as-is with no warranty ' expressed or implied. You may use this file at your own risk, ' and make modifications to it, as long as the copyright statement ' above remains with the source. ' ' SplitFilename ' ' A rudimentrary function to extract the base file name ' and file extension from a given file name. ' ' The extension is always returned in lower case, without the ' leading . prefixed. Returns "" on failure. ' Sub SplitFilename( ByVal Filename, ByRef BaseName, ByRef Ext ) BaseName = "" Ext = "" DotPos = InstrRev(Filename, ".") If DotPos > 0 Then BaseName = Left(Filename, DotPos - 1) Ext = Right(Filename, Len(Filename) - DotPos) End If BaseName = LCase(BaseName) Ext = LCase(Ext) End Sub Sub GotoRelatedSrc 'DESCRIPTION: Opens the .h or .cpp file that corresponds to the currently opened source file. BaseName = "" FileExt = "" ' Extract the file extension from the filename. ' SplitFilename ActiveDocument.FullName, BaseName, FileExt ' This macro only works with .h and .cpp files. ' If FileExt = "cpp" Or FileExt = "h" Then NewFileName = "" If FileExt = "cpp" Then NewFileName = BaseName + ".h" ElseIf FileExt = "h" Then NewFileName = BaseName + ".cpp" Else MsgBox "Unrecognized file extension.", vbOkOnly + vbExclamation, "Goto Related" End If If Not NewFileName = "" Then On Error Resume Next Documents.Open NewFileName End If Else MsgBox "This macro only works on C++ source files.", vbOkOnly + vbExclamation, "Goto Related" End If End Sub