Avatar of Justincut
Justincut
 asked on

How to switch between windows in Excel when the path is referenced in a Excel cell?

Hi Guys, I have an Excel Macro which opens a spreadsheet in the Cell "F7", then copies and pastes to another spreadsheet. See the code below. However, when I go Windows -> (so to return to the spreadsheet) how do I adapt  it in the code?

Sub Macro9()

    Workbooks.Open Filename:=Range("F7")

    Sheets("CV").Select
    Cells.Select
    Range("A17").Activate
    Selection.Copy
    Windows("01 - EMEA Mortgages Reporting Pack - Jan 15 (B) Test.xlsm").Activat
Microsoft ExcelSpreadsheetsVisual Basic Classic

Avatar of undefined
Last Comment
Rory Archibald

8/22/2022 - Mon
Saurabh Singh Teotia

Sub macro9()
Dim wb As Workbook, wb1 As Workbook

Set wb = ThisWorkbook

Set wb1 = Workbooks.Open(Range("F7").Value)

    Sheets("CV").Select
    Cells.Select
    Range("A17").Activate
    Selection.Copy
    
    wb.Activate

Open in new window


You can use the following code...

Saurabh...
ASKER CERTIFIED SOLUTION
Phillip Burton

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
Rory Archibald

You don't actually need to select or activate anything to copy ranges. What is the full purpose of the macro?
Experts Exchange is like having an extremely knowledgeable team sitting and waiting for your call. Couldn't do my job half as well as I do without it!
James Murphy