Open header file
Posted
by Meher Malakapalli
on October 15th, 1998
Sub OpenHeaderFile() DESCRIPTION: Opens a header file which is #included on the current line ActiveDocument.Selection.SelectLine LineText = ActiveDocument.Selection StartPos = Instr(LineText,"""") 'find the #include "" style If (StartPos = 0) Then StartPos = Instr(LineText, "<") 'find the #include <> style End If StartPos = StartPos + 1 'move to the start of the include file LineText = Mid(LineText,StartPos) EndPos = Instr(LineText,".h")' find the .h EndPos = EndPos + 1 'move to the end of the include file FileName = Mid(LineText,1,EndPos) PathName = ActiveDocument.Path + "\" ActiveDocument.Selection.EndOfLine 'remove selected stuff FullFileName = PathName+FileName on error resume next Documents.Open FullFileName End Sub

Comments
Updated VS2005/2008
Posted by britonleap on 02/20/2008 02:29pmI found this elsewhere, but it wasn't working so I've added enough to make it behave in my VS 2005/2008. Sorry for not having proper credit. BTW There is an Open Header in the popup menu, but not an Open Implementation. Often, ClassView will not fetch the implementation so this is useful. Sub HeaderFlip() 'DESCRIPTION: Open corresponding .h / .cpp file Dim currentFileName As String Dim newFileName As String Dim fno As Integer currentFileName = Application.ActiveDocument.FullName newFileName = "" If (UCase(Right(currentFileName, 2)) = ".H") Then newFileName = Left(currentFileName, Len(currentFileName) - 2) + ".CPP" ElseIf (UCase(Right(currentFileName, 4)) = ".CPP") Then newFileName = Left(currentFileName, Len(currentFileName) - 4) + ".H" End If On Error Resume Next If newFileName <> "" Then Application.Documents.Open(newFileName) End If End SubReplyUpdated Macro
Posted by Legacy on 10/26/2003 12:00amOriginally posted by: Mig
ReplyOpen Include File is Now a Feature
Posted by Legacy on 10/06/2001 12:00amOriginally posted by: No Longer Necessary in VC 6.0
Just right click on the include line of the file you want to open and choose, 'Open Document'.
Replyciulpk byby
Posted by Legacy on 07/31/2001 12:00amOriginally posted by: asad
shoodas, paprasciau su goto line
ReplyNot Clear !!!
Posted by Legacy on 05/21/1999 12:00amOriginally posted by: Sriram
Where should i write this macro & how does it get executed?????
ReplyDoesn't VC have this built-in?
Posted by Legacy on 05/11/1999 12:00amOriginally posted by: Yonat
When I left-click on a filename (without this macro), one of the pop-up menu items is "Open Documnet <filename>". What does this macro do that is different?
Replyit's very useful!
Posted by Legacy on 12/19/1998 12:00amOriginally posted by: james qiao
I find it's quite handy,and I can switch to .cpp or .h file very quickly.
ReplyCtrl+Shift+G (File, FileGoTo) works also with VC5
Posted by Legacy on 10/15/1998 12:00amOriginally posted by: Gert Rijs
Ctrl+Shift+G (File, FileGoTo) works also with VC5
Replyyou don't need to select anything, just make sure the cursor is on a filename.
VC will search all the standard places for the file