+ Reply to Thread
Results 1 to 4 of 4

VBA to copy cell from opened or closed workbook into another workbook

  1. #1
    Registered User
    Join Date
    04-23-2008
    Posts
    50

    VBA to copy cell from opened or closed workbook into another workbook

    Hello,
    I have the below code which copied cells from Phase3 WP6.xls into another file. It works perfectly when the Phase3 WP6.xls is not open. When I open it before I run the macro it does not work. Could you please help me to change it so it works no matter if the Phase3 WP6.xls is open and used by other users or closed. I would appreciate your help.
    Many thanks,


    Workbooks.Open Filename:="\\zzz\Phase3 WP6.xls", Password:="gold", ReadOnly:=True
    With GetObject("\\zzz\Phase3 WP6.xls")
    ThisWorkbook.Sheets("Sheet1").Range("A549:CS550").Value = .Sheets("WP6").Range("A75:CS76").Value

    .Close 0
    End With

  2. #2
    Forum Expert
    Join Date
    01-23-2013
    Location
    USA
    MS-Off Ver
    Microsoft 365 aka Office 365
    Posts
    3,863

    Re: VBA to copy cell from opened or closed workbook into another workbook

    Hi megtoma,

    Try the following code and/or the attached files which implement the code.
    Please Login or Register  to view this content.
    Lewis
    Attached Files Attached Files

  3. #3
    Registered User
    Join Date
    04-23-2008
    Posts
    50

    Re: VBA to copy cell from opened or closed workbook into another workbook

    Hi,
    The files you attached work perfectly. However, I must be doing sth wrong when I run the macro on my files...I changed the line: #Const megtoma = False to: #Const megtoma = True
    and it still asks me for the password...

  4. #4
    Forum Expert
    Join Date
    01-23-2013
    Location
    USA
    MS-Off Ver
    Microsoft 365 aka Office 365
    Posts
    3,863

    Re: VBA to copy cell from opened or closed workbook into another workbook

    Hi,

    You aren't doing anything wrong. The GetObject() construct has no way of obtaining a password when the file is closed. There may be workarounds (such as SendKeys or SendKeys alternatives that may allow the password to be pro grammatically entered).

    By the way, the GetObject() construct actually opens the Excel Workbook as an Excel file, This was the first time I have seen GetObject(), and originally thought it was a magic elixir that would allow access to closed Excel files, but that is not the case.

    There are alternatives that access Excel files, without opening Excel (which can be useful with very large Excel files) such as:
    a. ExecuteExcel4Macro() - Reference: http://msdn.microsoft.com/en-us/libr...ice.11%29.ASPX and
    b. ADO ( ActiveX Data Objects ) - Reference: http://www.xtremevbtalk.com/showthre...618#post969618

    I will try to do some research in the next couple of weeks and upload updates if and when I am successful.

    Lewis

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. [SOLVED] Copy a Worksheet from a Closed Workbook to the Current Opened Workbook
    By glennchung in forum Excel Programming / VBA / Macros
    Replies: 8
    Last Post: 08-28-2014, 12:55 PM
  2. [SOLVED] copy entire sheet from closed workbook and insert into another workboook when opened
    By tombie in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 05-03-2013, 03:26 AM
  3. Copy cell values from open workbook to closed workbook
    By merrener in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 08-24-2012, 03:14 AM
  4. copy a range from 2 closed workbooks to opened workbook
    By ahsanzafar in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 07-29-2012, 08:40 PM
  5. Replies: 1
    Last Post: 11-26-2011, 09:10 PM

Bookmarks

Posting Permissions

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

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1