Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 9
Default Open/Close files from Hyperlinks


Hi all,

I need a bit of help understanding hyperlinks. I want to create a VBA
function that opens an Excel file from a hyperlink, and another function
that closes the same file (without saving changes).

What I have is a spreadsheet with a list of file pathnames, which is a named
range. A VBA macro opens each Excel file in the list, extracts some data,
then closes each file. Rather than requiring the list be composed of
pathnames, I would like to allow users to specify hyperlinks to files on
other servers.

If you can offer some advice or point me to examples I would greatly
appreciate it.

Thanks,

-- Rev


  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 9
Default Open/Close files from Hyperlinks

Well I think I have this figured out. Here is some code I am using that will
open and close files based on a PathName that can begin with a driver
letter, server(i.e \\server\file...), or a URL. Feel free to comment, I am
sure there are better ways to do this.

Sub HyperOpen(PathRange)
' This will open a file specified by the hyperlink
ActiveWorkbook.FollowHyperlink Address:=PathRange
End Sub

I still need to add some error handling to this routine, but it works OK.
This will open any file given a string path PathRange, even if this is a
drive letter, server, or if the path is actually a URL.

Closing a file is a little trickier since the close method requires just the
file name, so I have to parse the string representing the path to just the
file name, or keep the whole string if the path is a URL.

Function HyperClose(Fname)
' If this is a hyperlink to URL, I do not need to manipulate the address.
' If this is going to a server or mapped drive, I need to get rid of all
' but the file name needs to be truncated to just file name.
If (InStr(1, Fname, "http") = 0) Then
CleanName = CleanFnameR(Fname)
Else
CleanName = Fname
End If
Workbooks(CleanName).Close SaveChanges:=False
End Function


Function CleanFnameR(Fname)
' Removes any sub directories from name. Recursive implementation
CleanFnameR = Fname
ilen = Len(Fname)
xlen = InStr(1, Fname, "\")
If (xlen 0) Then CleanFnameR = CleanFnameR(Right(Fname, ilen - xlen))
End Function



"Revolvr" wrote in message
news:lkimc.12074$k24.1317@fed1read01...

Hi all,

I need a bit of help understanding hyperlinks. I want to create a VBA
function that opens an Excel file from a hyperlink, and another function
that closes the same file (without saving changes).

What I have is a spreadsheet with a list of file pathnames, which is a

named
range. A VBA macro opens each Excel file in the list, extracts some data,
then closes each file. Rather than requiring the list be composed of
pathnames, I would like to allow users to specify hyperlinks to files on
other servers.

If you can offer some advice or point me to examples I would greatly
appreciate it.

Thanks,

-- Rev




Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
open and close files Chi Excel Worksheet Functions 2 May 28th 09 09:46 PM
fix for open/close files problem Patricia Shannon Excel Discussion (Misc queries) 0 April 25th 06 04:21 PM
fix for open/close files problem Patricia Shannon New Users to Excel 0 April 25th 06 04:21 PM
Hyperlinks to files open and then close instantaneously Rford626 Excel Discussion (Misc queries) 0 March 6th 06 10:30 PM
Open all linked files and close them. Malic Excel Programming 0 October 24th 03 08:20 PM


All times are GMT +1. The time now is 03:05 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"