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
 

Some videos you may like

Excel Facts

How to create a cell-sized chart?
Tiny charts, called Sparklines, were added to Excel 2010. Look for Sparklines on the Insert tab.

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 :)
 

Subscribe on YouTube

Watch MrExcel Video

Forum statistics

Threads
1,106,717
Messages
5,513,008
Members
408,930
Latest member
Michealker

This Week's Hot Topics

  • Sort code advice please
    Hi, I have the code below which im trying to edit but getting a little stuck. This was the original code which worked fine,columns A-F would sort...
  • SUMPRODUCT with nested If statement
    Hi everyone, Hope you're all well. I'm hoping someone will be able to point me in the right direction with a problem I'm having with a SUMPRODUCT...
  • VBA - simple sort is killing me!
    Hello all! This should be so easy, but not for me, apparently! I have a table of data that can be of varying lengths and widths. My current macro...
  • Compare Two Lists
    I have two Lists and I need to be able to Identify differences between them. List 100 comes from a workbook - the other is downloaded form the...
  • Formula that deducts points for each code I input.
    I am trying to create a formula that will have each student in my class start at 100 points and then for each code that I enter (PP for Poor...
  • Conditional formatting formula required for day of week and a value
    Hi, I have a really simple spreadsheet where column A is the date, column B is the activity total shown as a number and column C states the day of...
Top