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

Copy PDF to Excel
Select data in PDF. Paste to Microsoft Word. Copy from Word and paste to Excel.
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
 
Upvote 0
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
 
Upvote 0
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.
 
Upvote 0
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
 
Upvote 0

Forum statistics

Threads
1,214,644
Messages
6,120,709
Members
448,983
Latest member
Joaquim_Baptista

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
Back
Top