Application Launcher
Posted
by Omar Francisco
on August 7th, 1998
/*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:\data\xfiles\myproject.doc]. For a quick solution to send email see the code guru site. [http://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

Comments
Some other macro... under MS Office 2000
Posted by Legacy on 04/24/2001 12:00amOriginally posted by: Martin Vrbovsky
I've needed just searching some strings on the Web from Excel, and used code above. It searches the string in the cell mouse is over. I've edited like this:
(One bug - it does not remove or change blanks in the string to "+")
Sub Search()
'
' Search Macro
' Macro recorded 25/04/2001, Matko. Searching text from Active cell
'
' Key shortcut: Ctrl+p
'
Dim AppObject
Link= "http://search.internet.com/codeguru.earthweb.com?IC_QueryText="; + ActiveCell.FormulaR1C1
Set AppObject = CreateObject("InternetExplorer.Application.1")
AppObject.Visible = True
AppObject.Navigate (Link)
End Sub
ReplyCan not CreateObejct
Posted by Legacy on 05/10/1999 12:00amOriginally posted by: Michael Boyle
Microsoft has changed a couple of things in DevStudio between 5 and 6.
In 6, you can not longer call CreateObject.
A contact at Microsoft only said "the functionality was removed".
Now you can rewrite everything into a add-in, which would be a dll with is COM, and can still call CoCreateInstance.
Have fun.
Michael Boyle
ReplyError in CreateObject
Posted by Legacy on 04/22/1999 12:00amOriginally posted by: Manoj Vellanoore
I get an error saying Error in ActiveX control CreateObject.
ReplyError in CreateObject
Posted by Legacy on 04/21/1999 12:00amOriginally posted by: Narasimhan
This maybe due to vbscript security, try using SP2 it may fix the problem. This was supposed to work properly in VC++ 5.
Reply
This macro don't like me too much
Posted by Legacy on 03/13/1999 12:00amOriginally posted by: Anton Bazarsky
Just like Stefan wrote , it fail on CreateObject.
ReplyError in CreateObject
Posted by Legacy on 11/12/1998 12:00amOriginally posted by: Stefan Gartz
I can not get this macro working, I get an error saying Cannot CreateObject in this Activex control.
What am I doing wrong?
I am using Visual C++ 6.0 proffessional edition.
Regards
ReplyStefan Gartz
Application Launcher
Posted by Legacy on 11/12/1998 12:00amOriginally posted by: Rex Myer
This is real cool. I read on the CreateObject stuff but couldn't
understand it. This helped immensely. I wonder if you could tell me
where you picked up the various object calls. For instance for Word you
call AppShow but for Excel you call Visible = True. How did you find
this out? Also you have a todo comment in there to open any registered
extension by the Explorer Shell GUIDs. Have you done this yet?
Thanks for your contribution!
Reply