Application Launcher | CodeGuru

Application Launcher

As I develop my code, I find myself constantly looking for information about a particular API in the MSDN CD-ROMs, the Microsoft web site and sometimes all over the Internet. When I find links relevant to the work at hand, I copy and paste them as comment into my code. Whenever I want to reference […]

Written By
CodeGuru Staff
CodeGuru Staff
Aug 7, 1998
1 minute read
CodeGuru content and product recommendations are editorially independent. We may make money when you click on links to our partners. Learn More

As I develop my code, I find myself constantly looking for information about
a particular API in the MSDN CD-ROMs, the Microsoft web site and sometimes all
over the Internet. When I find links relevant to the work at hand, I copy and
paste them as comment into my code. Whenever I want to reference this
information again, I copy the link into my browser and away it goes. After doing
this a few times, I knew there had to be a better way, that is how the LaunchApp
macro was born. LauchApp allows you to fire up links from within a comment block
to Word, Excel, Access, Power Point, Visio and Html files. The macro can be
extended to handle any file type (PDF, Corel Draw, etc) you or your team include
in your code documentation. The following code fragment shows a typical use of
the macro.

/*CustomRecipient
Creates a custom recipient in MS Exchange Global address list. For more
information on the technique used in this function and other aspects of
DAPI see [mk:@ivt:kb/source/mapi/q165931.htm].
For information on the interface design for this class see [d:dataxfilesmyproject.doc].
For a quick solution to send email see the code guru site. [https://www.codeguru.com/internet/imapi.shtml]

CustomRecipient(LPSTR strRecipient)
{
	// Your code goes here
}
*/

To access any of the links embeded in your comment, all you need to do is place the cursor
anywhere within the [ ] pair and lauch the LaunchApp macro. The macro will bring the proper
application with the document or link loaded. Needless to say that you will save time by adding
this macro to a tool bar or keyboard pair of keys.

Sub LaunchApp()
‘DESCRIPTION: Launch link or document embeded in comment block
	‘Get the current cursor positon
	cpos = ActiveDocument.Selection.CurrentColumn
	‘Select, capture current line and convert tabs to spaces
	ActiveDocument.Selection.SelectLine
	ActiveDocument.Selection.Untabify
	Link = ActiveDocument.Selection.Text
	‘Restore tabs
	ActiveDocument.Undo
	‘Delete return&linefeed at the end of line
	Link = Left(Link,Len(Link)-2)
	‘ Split selected line at cpos – Check for Rpos at end of line
	Rpos = Len(link)-cpos
	if Rpos <= 0 then
		Rside = ""
	else
		Rside = Right(Link,Len(Link) – cpos)
	end if
	Lside = Left(Link, cpos)
	‘ Get text within [ ] pair
	bpos = InstrRev(Rside, "]", -1)
	if bpos > 0 then
		Rside = Left(Rside,  bpos – 1  )
	else
	    Rside = ""
		Lside = Left(Lside, Len(Lside) – 1) ‘ ] is included in left side
	end if
	Lside = Right(Lside,Len(Lside) – InstrRev(Lside, "[", -1))
	Link = Lside & Rside
	‘ Open link – If no application is found default is web browser
	if Link <> "" then
		‘ Trim tab and spaces from selected text.
		Do While InStr(Link, vbTab) <> 0
			Link = Right(Link, Len(Link) – InStr(Link, vbTab))
		Loop
		Link = Trim(Link)
		‘ Determine file type by looking at the extension
		ExtPos = InstrRev(Link, ".", -1, 1)
		‘ An extension must exist in order to process the selected text
		if ExtPos > 0 then
			Ext = LCase(Right(Link,Len(Link)-ExtPos))
			‘ This is the object to handle the selected application.  See
			‘ [mk:@ivt:project/project/pssvba/mod3les3.htm] for object information
			‘ TODO$: Use Shell or Explorer object to handle any registered file format.
			Dim AppObject
			Select Case Ext
				Case "doc", "rtf"		‘MS word
					Set AppObject = CreateObject("Word.Basic")
					AppObject.AppShow
					AppObject.FileOpen Link
				Case "xls"				‘MS Excel
					Set AppObject = CreateObject("Excel.Application")
					AppObject.Visible = True
					AppObject.Workbooks.Open Link
				Case "ppt"				‘MS Power Point
					Set AppObject = CreateObject("PowerPoint.Application")
					AppObject.Visible = True
					AppObject.Presentations.Open Link
				Case "mdb"				‘MS Access
					Set AppObject = CreateObject("Access.Application")
					AppObject.Visible = True
					AppObject.OpenCurrentDatabase Link
				Case "vsd"				‘Visio
				    Set AppObject = CreateObject("visio.application")
					AppObject.Documents.Open Link
				Case Else				‘ Internet Explorer
					Set AppObject = CreateObject("InternetExplorer.Application.1")
					AppObject.Visible = True
					AppObject.Navigate(Link)
			End Select
		else
			MsgBox("The text you have selected does not have a valid file extension.")
		end if
	end if
End Sub
CodeGuru Logo

CodeGuru covers topics related to Microsoft-related software development, mobile development, database management, and web application programming. In addition to tutorials and how-tos that teach programmers how to code in Microsoft-related languages and frameworks like C# and .Net, we also publish articles on software development tools, the latest in developer news, and advice for project managers. Cloud services such as Microsoft Azure and database options including SQL Server and MSSQL are also frequently covered.

Property of TechnologyAdvice. © 2026 TechnologyAdvice. All Rights Reserved

Advertiser Disclosure: Some of the products that appear on this site are from companies from which TechnologyAdvice receives compensation. This compensation may impact how and where products appear on this site including, for example, the order in which they appear. TechnologyAdvice does not include all companies or all types of products available in the marketplace.