'Declare WB as public where file name is based on cell value

I need help on declaring 2 workbooks globally where the workbook name is based on a cell value.

I have 3 workbooks workbook

  1. "UPSHI" (file name does not change) workbook
  2. "UAH DR_M04 2022"(M04 and 2022 changes monthly depending in month & year) workbook
  3. "2022_M04_OP21_AAH"(2022, M04 & OP21 changes monthly).

UPASHI workbook will be my main file which will create all my buttons and formulas, I created formula in cell B1 for the 2nd workbook that will identify the current name of the 2nd workbook and another formula in cell B7 to identify current name of my 3rd workbook.

I used cell B1 & B7 to activate the workbooks which work fine but I cannot make it work when i want to copy a sheet from workbook 2 to my workbook 3.

I wanted to declare a global variable for each workbook that I can just call when I want to activate or select the work book, how can I make it work?.

Here is my current code:

Sub PrepFile_Click()
    Workbooks(ActiveSheet.Range("b1").Value).Activate
    Application.DisplayAlerts = False
    Sheets("Upstream Asset Hierarchy -OLD").Delete
    Application.DisplayAlerts = True
    Sheets("Upstream Asset Hierarchy Viewer").Name = "Upstream Asset Hierarchy -OLD"
            
    Workbooks("UPASHI Automation File").Activate
    Workbooks(ActiveSheet.Range("b7").Value).Activate
    Sheets("Upstream Asset Hierarchy Viewer").Copy before:=Workbooks(ActiveSheet.Range("b1").Value).Sheets("UPSASSET")
End Sub


Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source