Question : Excel VBA to open other excel file and copy cell value to active excel sheet

The code below should open the file path that is stored as string/value in range named "FilePath" and get the value form cell A1 in the opened sheet, copy it to range "CopiedValue" in the sheet with the code and close the opened book without saving.

Unfortunately, my version does not work... any help appreciated.
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
Sub GetHistData()
    'open hist file
    FilePath = Range("FilePath").Value
    Workbooks.Open Filename:=FilePath
    Sheets("Sheet1").Select
    'copy data from hist file
    Range("a1").Copy
    'activate working file
    ThisWorkbook.Activate
    Sheets("Sheet1").Activate
    'copy values to destination cell
    Range("CopiedValue").Select
    Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
        :=False, Transpose:=False
    Workbooks(HistSheetPath).Close
End Sub
Attachments:
 
file with code discussed
 

Answer : Excel VBA to open other excel file and copy cell value to active excel sheet

Sub GetHistData()
    'open hist file
    Dim mwb As Workbook
    FilePath = Range("FilePath").Value
    Set mwb = Workbooks.Open(Filename:=FilePath)
    mwb.Sheets("Sheet1").Range("A1").Copy
    ThisWorkbook.Sheets("Sheet1").Range("CopiedValue").PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
        :=False, Transpose:=False
    Workbooks(mwb.Name).Close False
End Sub
Random Solutions  
 
programming4us programming4us