#1   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 20
Default Hyperlink on Save

When you create a file name under "Save As", is it possible (through a macro)
at the same time to automatically create a hyperlink to that "file name and
path" in a specific cell?
  #2   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 3,365
Default Hyperlink on Save

Yes, but...
I think you'd be better off doing it in the Workbook's _BeforeClose() event
rather than the _BeforeSave() event. BeforeSave doesn't see the changed path
if you decide to store it in a folder other than the current folder.

Private Sub Workbook_BeforeClose(Cancel As Boolean)
On Error Resume Next
Worksheets("Sheet1").Range("A1").Formula = _
"=HYPERLINK(" & Chr$(34) & ThisWorkbook.FullName & Chr$(34) _
& "," & Chr$(34) & "Link to this file" & Chr$(34) & ")"
On Error GoTo 0
End Sub

Change the sheet name and cell address as required, and you can change the
text displayed from "Link to this file" to anything you want, including the
..FullName of the workbook again.

To put the code in the proper place (Excel 2003 & earlier): right-click on
the Excel icon immediately to the left of the word "File" in the menu toolbar
and choose [View Code] from the popup list. Copy and paste the code into the
code module presented to you.

If you want to put that into some other workbook, as in building a 'table of
contents' workbook, there's more work to be done. I'm not certain what the
practical advantage of putting it in the same workbook is: if you can see it,
you have the book open and you already know where it came from? Also, you
can't click and use it because you'll get a "file is already open" alert.


"I think I need to rephrase the question" wrote:

When you create a file name under "Save As", is it possible (through a macro)
at the same time to automatically create a hyperlink to that "file name and
path" in a specific cell?

  #3   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 35,218
Default Hyperlink on Save

If you just want a hyperlink that points to a specific location in the same
workbook, then you can use the =hyperlink() function. It won't depend on the
location of that workbook.

David McRitchie posted this and it might help you:

=HYPERLINK("#"&CELL("address",C5),C5)
=HYPERLINK("#"&CELL("address",sheetone!C5),sheeton e!C5)
=HYPERLINK("#"&CELL("address",'sheet two'!C5),'sheet two'!C5)

I think I need to rephrase the question wrote:

When you create a file name under "Save As", is it possible (through a macro)
at the same time to automatically create a hyperlink to that "file name and
path" in a specific cell?


--

Dave Peterson
  #4   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 20
Default Hyperlink on Save

Thanks for the information. It works perfectly.

"JLatham" wrote:

Yes, but...
I think you'd be better off doing it in the Workbook's _BeforeClose() event
rather than the _BeforeSave() event. BeforeSave doesn't see the changed path
if you decide to store it in a folder other than the current folder.

Private Sub Workbook_BeforeClose(Cancel As Boolean)
On Error Resume Next
Worksheets("Sheet1").Range("A1").Formula = _
"=HYPERLINK(" & Chr$(34) & ThisWorkbook.FullName & Chr$(34) _
& "," & Chr$(34) & "Link to this file" & Chr$(34) & ")"
On Error GoTo 0
End Sub

Change the sheet name and cell address as required, and you can change the
text displayed from "Link to this file" to anything you want, including the
.FullName of the workbook again.

To put the code in the proper place (Excel 2003 & earlier): right-click on
the Excel icon immediately to the left of the word "File" in the menu toolbar
and choose [View Code] from the popup list. Copy and paste the code into the
code module presented to you.

If you want to put that into some other workbook, as in building a 'table of
contents' workbook, there's more work to be done. I'm not certain what the
practical advantage of putting it in the same workbook is: if you can see it,
you have the book open and you already know where it came from? Also, you
can't click and use it because you'll get a "file is already open" alert.


"I think I need to rephrase the question" wrote:

When you create a file name under "Save As", is it possible (through a macro)
at the same time to automatically create a hyperlink to that "file name and
path" in a specific cell?

  #5   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 20
Default Hyperlink on Save

Thanks for the information.

"Dave Peterson" wrote:

If you just want a hyperlink that points to a specific location in the same
workbook, then you can use the =hyperlink() function. It won't depend on the
location of that workbook.

David McRitchie posted this and it might help you:

=HYPERLINK("#"&CELL("address",C5),C5)
=HYPERLINK("#"&CELL("address",sheetone!C5),sheeton e!C5)
=HYPERLINK("#"&CELL("address",'sheet two'!C5),'sheet two'!C5)

I think I need to rephrase the question wrote:

When you create a file name under "Save As", is it possible (through a macro)
at the same time to automatically create a hyperlink to that "file name and
path" in a specific cell?


--

Dave Peterson

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
Excel 2007 save to PDF - hyperlink LTJ Excel Discussion (Misc queries) 1 August 24th 07 09:45 AM
My Hyperlink bonks out after I save the file! masterbaker Excel Worksheet Functions 2 August 1st 06 09:35 PM
hyperlink to sheet in formula, can't save under new filename Franky Excel Worksheet Functions 0 April 21st 06 04:20 PM
hyperlink base did not save Patricia Shannon Links and Linking in Excel 1 February 17th 06 11:53 PM
My hyperlink in an excel spreadsheet will not save. sheilag Excel Discussion (Misc queries) 3 September 14th 05 03:57 PM


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

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

About Us

"It's about Microsoft Excel"