adrianadik
New Member
- Joined
- Aug 28, 2014
- Messages
- 4
Hi all,
I'm trying to create VBA code which opens file from external drive, than copies selected sheet and pastes it into active workbook. That's what I've done so far:
Code opens workbook but (I suppose) it treats already opened workbook (source) as 'this workbook'.
Is there any way to copy sheet from opened file?
Regards from Poland
I'm trying to create VBA code which opens file from external drive, than copies selected sheet and pastes it into active workbook. That's what I've done so far:
Code:
Sub CopyWorksheet(control As IRibbonControl)
Application.ScreenUpdating = False
Application.DisplayAlerts = False
Dim wbSource As Workbook, wbDest As Workbook
Dim wsSource As Worksheet, wsDest As Worksheet
Set wbSource = Workbooks.Open("FILE PATH\file.xlsx", , True)
Set wsSource = wbSource.Worksheets(1)
Set wbDest = ThisWorkbook
Set wsDest = Sheets(1)
wbSource.ws.Source.Copy wbDest.wsDest
wbSource.Close
Application.ScreenUpdating = True
Application.DisplayAlerts = True
End Sub
Code opens workbook but (I suppose) it treats already opened workbook (source) as 'this workbook'.
Is there any way to copy sheet from opened file?
Regards from Poland