Returning to current workbook regardless of name

fatduck

New Member
Joined
Jun 26, 2008
Messages
13
Hi there

I'm writing a macro which opens and operates in a separate workbook (FileB) to that which it is stored in (FileA). The problem is that I need it to bring data back from FileB to File A, but the name of File A is not constant and so I can't simply instruct it to activate the workbook by referencing its name. Is there some way to tell a macro to activate the workbook it is stored in, without having to specify the name of that workbook?

Thanks so much for any help!
 

Makrini

Well-known Member
Joined
May 22, 2007
Messages
1,035
Hi and welcome to the board!

You can use "ThisWorkbook"

Thisworkbook.activate

"thisWorkbook" is the workbook that the macro is in...

"ActiveWorkbook" is the one that is activated
 

Makrini

Well-known Member
Joined
May 22, 2007
Messages
1,035
No problem - actually I only realized this the other day.

Until then I had been assigning the original workbook name to a variable..

sOriginalFile = ActiveWorkbook.Name

before opening the second workbook...
 

Forum statistics

Threads
1,081,543
Messages
5,359,431
Members
400,526
Latest member
Brook1083

Some videos you may like

This Week's Hot Topics

  • VBA (Userform)
    Hi All, I just would like to know why my code isn't working. Here is my VBA code: [CODE=vba]Private Sub OKButton_Click() Dim i As Integer...
  • List box that changes fill color
    Hello, I have gone through so many pages trying to figure this out. I have a 2020 calendar that depending on the day needs to have a certain...
  • Remove duplicates and retain one. Cross-linked cases
    Hi all I ran out of google keywords to use and still couldn't find a reference how to achieve the results of a single count. It would be great if...
  • VBA Copy and Paste With Duplicates
    Hello All, I'm in need of some input. My VBA skills are sub-par at best. I've assembled this code from basic research and it works but is...
  • Macro
    is it possible for a macro to run if the active cell value is different to the value above it
  • IF DATE and TIME
    I currently use this to check if date has passed but i also need to set a time on it too. Is it possible? [CODE=vba]=IF(B:B>TODAY(),"Not...
Top