PDA

View Full Version : Copy cells from open or closed workbook



megtoma
09-08-2014, 07:37 AM
Hello,
The below code works when the file zzz.xls is not open but when someone is using the zzz.xls file, I get an error message. Could anyone please help me to change that code so it works no matter if the file is open or closed? I would appreciate your help.
Many thanks,


Workbooks.Open Filename:="\\zzzz\zzz.xls (file://\\zzzz\zzz.xls)", Password:="gold", ReadOnly:=True
With GetObject("\\zzzz\zzz.xls (file://\\zzzz\zzz.xls)")
ThisWorkbook.Sheets("Controls Tracker P3").Range("B6:N205").Value = .Sheets("Examination").Range("C3:O202").Value
ThisWorkbook.Sheets("Controls Tracker P3").Range("O6:O205").Value = .Sheets("Examination").Range("Q3:Q202").Value
.Close 0
End With
End Sub

GTO
09-09-2014, 03:16 AM
My poor pea-brain is not exactly 'getting' what are rendering issues vs. the code you intended to post. Conceptually, see if you already have the workbook(wb) opened. If yes, set a reference to it. If not, set a reference to a opened-as-read-only copy.

Does that make sense?

Mark

Aflatoon
09-10-2014, 12:49 AM
I don't see the point in opening the workbook then using GetObject.