We help IT Professionals succeed at work.

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
Comment
Watch Question

Top Expert 2015

Commented:
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...
Director, Practice Manager and Computing Consultant
Awarded 2014
Top Expert 2014
Commented:
Do I understand you correctly when you say that you want to go back to the original window?
 
If so, start with
 
Set myWindow = ActiveWindow
 
and end with
 
myWindow.Activate
Most Valuable Expert 2011
Top Expert 2011

Commented:
You don't actually need to select or activate anything to copy ranges. What is the full purpose of the macro?