Solved

VBA Excel - Assign saved filename and path to variable

Posted on 2010-11-26
5
771 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
5 Comments
 
LVL 23

Expert Comment

by:Michael74
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:
Michael74 earned 500 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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

This article will guide you to convert a grid from a picture into Excel format using Microsoft OneNote and no other 3rd party application.
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.
Graphs within dashboards are meant to be dynamic, representing data from a period of time that will change each time the dashboard is updated with new data. Rather than update each graph to point to a different set within a static set of data, t…
Many functions in Excel can make decisions. The most simple of these is the IF function: it returns a value depending on whether a condition you describe is true or false. Once you get the hang of using the IF function, you will find it easier to us…

734 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