Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Hyperlink help needed

Status
Not open for further replies.

jreinhart

Technical User
May 30, 2003
7
AU
I am having trouble creating multiple hyperlinks to their associated autocade files on my computer.
I can easily create a hyperlink to the files by entering a hyperlink for each individually but I need want my entered data ie a1 or b4 to be directly converted so it will access c:\a1.dwg or c:\b4.dwg.

I have tried to change the data type to hyperlink and it sort of does what i want but they link directly to or
Does anyone know how to change the http:// to c:\?

Thanks
 
Not sure I understand you completely, but this may be what you are after:
[blue]
Code:
Sub CreateFileLinks()
[green]
Code:
' Select a range of cells.
' Each selected cell will be converted into
'    a file link with the cell address as
'    the file name.
[/color]
Code:
Const LINK_PATH = "c:\"
Const FILE_EXTENSION = ".dwg"
Dim c As Range
 For Each c In Selection
  ActiveSheet.Hyperlinks.Add Anchor:=c, _
  Address:=LINK_PATH & c.Address(0, 0) & FILE_EXTENSION
 Next c
End Sub
[/color]

 
Thanks for your help.
Although it is not what I needed it really helping me understand code (its been a while...) What i need is a lot simpler and here is some code that I have written that will hopefully help clarify what I am trying to do. I am getting an error at "run filedirectory".

Private Sub DwgNo_Click()
Dim FileName
Dim FilePath
Dim Fileext
Dim Filedirectory
FileName = DwgNo
Fileext = ".txt"
FilePath = "C:\"
Filedirectory = FilePath & FileName & Fileext
If Filedirectory = "" Then MsgBox "File Not Found"
If Filedirectory <> &quot;&quot; Then
Run Filedirectory

End If

End Sub
 
Still not clear on what you are doing. Are you using a form? In any event, &quot;Run&quot; does not run an external program (check the help file)

Perhaps this is closer to what you need:
[blue]
Code:
Option Explicit

Private Sub DwgNo_Click()
  OpenDwgFile &quot;1145&quot;
End Sub

Sub OpenDwgFile(DwgNo As String)
Const FILE_PATH = &quot;C:\&quot;
Const FILE_EXT = &quot;.txt&quot;
Const APP_NAME = &quot;Notepad.exe&quot;
Dim sPathAndFile As String
  sPathAndFile = FILE_PATH & DwgNo & FILE_EXT
  With Application.FileSearch
    .NewSearch
    .LookIn = FILE_PATH
    .SearchSubFolders = False
    .FileName = sPathAndFile
    .MatchTextExactly = True
    .FileType = msoFileTypeAllFiles
    If .Execute() = 1 Then
      Shell APP_NAME & &quot; &quot; & sPathAndFile, vbNormalFocus
    Else
      MsgBox &quot;File &quot; & sPathAndFile & &quot; Not Found&quot;
    End If
  End With
End Sub
[/color]


 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top