HOWTO: Hyperlink in UserDocumentsLast reviewed: November 25, 1997Article ID: Q177238 |
The information in this article applies to:
SUMMARYThis article illustrates how to use the hyperlink object from a UserDocument (Visual Basic Active Document) to navigate to another document. It demonstrates the following:
MORE INFORMATIONFrom your UserDocument, you can jump to other UserDocuments that are in your application (Internal Jumping) or you can jump to other Web locations or documents (External Jumping). In both cases, you use the Hyperlink object's NavigateTo method and supply an absolute URL to where you want to jump. For example, you can do the following from your UserDocument code:
Hyperlink.NavigateTo "http://www.microsoft.com"This will cause Internet Explorer to navigate to the specified location. You can also use this method for jumping to other UserDocuments in your application. Because you have to specify an absolute URL, using this approach for other UserDocuments on a Web site requires extra work. You need to know the full URL from which the document (.vbd) was launched. You can get this information using Parent.LocationURL from your UserDocument code. The location can be either a Web URL or a UNC file location name. NOTE: You should use the Parent.LocationURL property for retrieving the location of the UserDocument. Parent.LocationURL, unlike Parent.LocationName, works identically in both Internet Explorer 3 and Internet Explorer 4. In Internet Explorer 3, LocationName returns the complete path just as LocationURL does. In Internet Explorer 4, LocationName does not always return a complete path. You should not use App.Path because it returns the location where your EXE or DLL exists locally, not the location from where the VBD was downloaded.
Constructing an Absolute URLAs mentioned before, you need an absolute URL for Hyperlink.NavigateTo method. This can be tricky for jumping to other UserDocuments in your application because the UserDocuments can reside on a local (or network) file or on a Web server. The following function takes the value returned by Parent.LocationURL, strips off the filename, and returns a path string. You can then append the name of any UserDocument that resides at the same base URL as the current document to the path string, and use the final result to call NavigateTo:
Function PathFromURL(iURL As String) As String 'Returns the path of the given URL. Works for both files and Web URLs 'the final / or \ is also returned so you can append your own filename ' 'http://www.microsoft.com/default.asp -> http://www.microsoft.com/ 'c:\demos\doc1.vbd -> c:\demos\ Dim I As Integer Dim Last As Integer Dim C As String * 1 For I = Len(iURL) To 1 Step -1 C = Mid$(iURL, I, 1) If C = "\" Or C = "/" Then Last = I Exit For End If Next If Last > 0 Then PathFromURL = Left$(iURL, Last) Else PathFromURL = "" End If End FunctionAs an example, suppose you have a Doc1.VBD and a Doc2.VBD stored on a server at http://demo/hyperlink, but you do not want to hardcode the server name in your code so that these VBD files can be moved easily from one server location to another. To jump from Doc1.vbd to Doc2.vbd, you can use the above function as follows:
Hyperlink.NavigateTo PathFromURL(Parent.LocationURL) + "doc2.vbd"Because PathFromURL can work on both URLs and UNC, this technique will work in both cases without changing code. Also, note that PathFromURL returns the final / or \, so you simply need to append your .vbd file name.
|
Additional query words: LocationName, LocationURL, Hyperlink
© 1998 Microsoft Corporation. All rights reserved. Terms of Use. |