Macro Save Workbook Name for (Re)Activate

ChuckRobert

Board Regular
Joined
Feb 26, 2009
Messages
64
I am trying to run a macro from workbook A that opens workbook B (containing appointments), copies required data and paste it into workbook A.

The challenge I have is that workbook A is renamed each week as 05/18/2009.xls....05/25/2009.xls. (etc.) so if I hard code the re-activate workbook A (to paste) with the current workbook name will not work next week once re-named.

Could I get a suggestion on code that would enable the Macro to first look for the current workbook name, then use that reference to re-activate the sheet later in the code?
 

Norie

Well-known Member
Joined
Apr 28, 2004
Messages
75,362
Office Version
365
Platform
Windows
Well don't hardcode and don't 're-activate'.:)

Create a reference to the workbook (A?) the code is in like this:
Code:
Set wbThis = ThisWorkbook
You can now use this in the rest of the code whenever you want to refer to that workbook, for example to activate it.
Code:
wbThis.Activate
But you shouldn't need to activate anyway, but that's hard to tell without seeing some of your code.:)
 

Forum statistics

Threads
1,082,043
Messages
5,362,836
Members
400,694
Latest member
Sofie17

Some videos you may like

This Week's Hot Topics

  • populate from drop list with multiple tables
    Hi All, i have a drop list that displays data, what i want is when i select one of those from the list to populate text from different tables on...
  • Find list of words from sheet2 in sheet1 before a comma and extract text vba
    Hi Friends, Trying to find the solution on my task. But did not find suitable one to the need. Here is my query and sample file with details...
  • Dynamic Formula entry - VBA code sought
    Hello, really hope one of you experts can help with this - i've spent hours on this and getting no-where. .I have a set of data (more rows than...
  • Listbox Header
    Have a named range called "AccidentsHeader" Within my code I have: [CODE]Private Sub CommandButton1_Click() ListBox1.RowSource =...
  • Complex Heat Map using conditional formatting
    Good day excel world. I have a concern. Below link have a list of countries that carries each country unique data. [URL...
  • Conditional formatting
    Hi good morning, hope you can help me please, I have cells P4:P54 and if this cell is equal to 1 then i want row O to say "Fully Utilised" and to...
Top