Consulting

Results 1 to 3 of 3

Thread: Copy cells from open or closed workbook

  1. #1
    VBAX Regular
    Joined
    Mar 2011
    Posts
    23
    Location

    Copy cells from open or closed workbook

    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", Password:="gold", ReadOnly:=True
    With GetObject("\\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
    Last edited by SamT; 09-08-2014 at 03:25 PM. Reason: Added Code Tags with # Icon

  2. #2
    Knowledge Base Approver VBAX Guru GTO's Avatar
    Joined
    Sep 2008
    Posts
    3,368
    Location
    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

  3. #3
    VBAX Master Aflatoon's Avatar
    Joined
    Sep 2009
    Location
    UK
    Posts
    1,720
    Location
    I don't see the point in opening the workbook then using GetObject.
    Be as you wish to seem

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •