calling back file location and using it in formula

taz23340

Active Member
Joined
Jun 11, 2003
Messages
336
hello everyone,

I am having an issue with the file location my formula is reading. Our IT dept is changing the folder locations and as such I would like to have a macro that i dont have to update every second day.

current scenario-we use windows exploder to access the macro, open it. then open our data dump or transfer and run the macro once we are in cell a1.

however when i run the below code, a open file dialog box opens.

Range("a21:av21").Value = "=VLOOKUP(A20,'K:\SpreadsheetBilling\MISC\MACROS\[E51_Macro_Bilingual_August_2010.xls]Headers'!$A$1:$C$50,3,FALSE)"

as you can see it is a network drive.

I would like make the macro start off by finding the location of the file the macro is in, not the one im going to run the macro on.

all the code i can find that will find the location is `getfilename` but that is asking for a location, however i want it to give me the location and then use that location in the above formula.

i hope this is possible.
please let me know.
kevin
 

Excel Facts

Fastest way to copy a worksheet?
Hold down the Ctrl key while dragging tab for Sheet1 to the right. Excel will make a copy of the worksheet.

Richard Schollar

MrExcel MVP
Joined
Apr 19, 2005
Messages
23,707
Hi Kevin

So do you want the filepath of the file in which the macro actually resides? That is avalable from:

Code:
Msgbox ThisWorkbook.Path
 

taz23340

Active Member
Joined
Jun 11, 2003
Messages
336
Hello Richard,

Yes I want the filepath of the workbook that the macro resides.

Will the below give me a msg box?

how would i use this address in the vlookup formula from my first post.

just to let you know this macro will be used by others who do not write vba as such I would this part to be transparent to them.

thanks for the help.
kevin
 

Richard Schollar

MrExcel MVP
Joined
Apr 19, 2005
Messages
23,707
Well, you just need to incorporate it into the macro code like this:

Code:
Range("a21:av21").Value = "=VLOOKUP(A20,'" & ThisWorkbook.Path & "\[" & ThisWorkbook.Name & "]Headers'!$A$1:$C$50,3,FALSE)"

I also included the filename above as well.
 

taz23340

Active Member
Joined
Jun 11, 2003
Messages
336
Ok thanks richard I will try this.

From what I see, I do not have to use the msg box suggestion of before, is that correct?

thanks for your help.
kevin
 

Richard Schollar

MrExcel MVP
Joined
Apr 19, 2005
Messages
23,707
Yes that's correct - the MSgBox was only included to demonstrate the ouput of ThisWorkbook.Path :)
 
Master Excel Bundle

Excel contains over 450 functions, with more added every year. That’s a huge number, so where should you start? Right here with this bundle.

Forum statistics

Threads
1,163,419
Messages
5,831,512
Members
430,073
Latest member
Casper01

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Top