Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

VBA Excel - Assign saved filename and path to variable

Posted on 2010-11-26
5
Medium Priority
?
808 Views
Last Modified: 2012-06-21
Dear Experts,

I have a small macro by recorder below, it just save the actual excel file to directory D:\ASN \Test.xls

    ChDir "D:\ASN"
    ActiveWorkbook.SaveAs Filename:="D:\ASN\Test.xls", FileFormat:=xlNormal, _
        Password:="", WriteResPassword:="", ReadOnlyRecommended:=False, _
        CreateBackup:=False

Could you please advise how to assign this saved filename to a variable, which after would be copied by the macro to Sheet2 as clickable hyperlink to cell A1?

thanks,
0
Comment
Question by:csehz
  • 3
  • 2
5 Comments
 
LVL 23

Expert Comment

by:Michael Fowler
ID: 34216819
csehz

Here you go
Sub fileName()
   
   Sheets(2).Hyperlinks.Add Anchor:=Sheets(2).Range("A1"), Address:=ThisWorkbook.Path, _
        TextToDisplay:=ThisWorkbook.Path

End Sub

Open in new window

0
 
LVL 1

Author Comment

by:csehz
ID: 34216828
Maybe a small addition about the target - when I am working on a file and finally finished, I would like to have a small macro which would know the path of the saved file and would be able to copy to a beside sheet as hyperlink.

thanks,
 
0
 
LVL 1

Author Comment

by:csehz
ID: 34216846
Michael thanks, trying your macro it copied to A1 the D:\ASN, could you advise how to modifiy that not only the directory, but also the file name would be there? So D:\ASN\Test.xls

thanks,
0
 
LVL 23

Accepted Solution

by:
Michael Fowler earned 2000 total points
ID: 34216922
Sorry about that it is getting late here. This will work for you
Sub fileName()
   Sheets(2).Hyperlinks.Add Anchor:=Sheets(2).Range("A1"), Address:=ThisWorkbook.FullName, _
        TextToDisplay:=ThisWorkbook.FullName
End Sub

Open in new window

0
 
LVL 1

Author Closing Comment

by:csehz
ID: 34216954
Never mind it was very good speed, thanks it works of course
0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article descibes how to create a connection between Excel and SAP and how to move data from Excel to SAP or the other way around.
If you need to forecast numbers -- typically for finance -- the Windows and Mac versions of Excel 2016 have a basket of tools to get the job done.
The viewer will learn how to create two correlated normally distributed random variables in Excel, use a normal distribution to simulate the return on different levels of investment in each of the two funds over a period of ten years, and, create a …
This Micro Tutorial will demonstrate in Google Sheets how to use the HYPERLINK function to create live links inside your spreadsheet.

972 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question