Open header file

CodeGuru content and product recommendations are editorially independent. We may make money when you click on links to our partners. Learn More.

Th following macro opens a header file included on the current line (just like
right-click on the header file name and choosing Open filename.h).

Sub OpenHeaderFile()
DESCRIPTION: Opens a header file which is #included on the current line

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

More by Author

Get the Free Newsletter!

Subscribe to Developer Insider for top news, trends & analysis

Must Read