+ Reply to Thread
Results 1 to 2 of 2

HELP Getting data from closed workbook using VBA code

Hybrid View

  1. #1
    Registered User
    Join Date
    04-24-2013
    Location
    Perth, Australia
    MS-Off Ver
    Excel 2010
    Posts
    2

    Question HELP Getting data from closed workbook using VBA code

    Hi,

    I'm getting a Run-time error '91': Object variable or With block variable not set

    Set wb = Workbooks.Open("T:\Data\LMS Leads Conversion.xlsm", True, True)
    ' the sheet in this workbook to copy to
    With ThisWorkbook.Worksheets("LMS Data")
    ' read data from the source workbook
    'the range to copy to in this workbook-name of sheet to copy FROM-range in closed workbook to copy
    .Range("B7", "AR174").Formula = wb.Worksheets("Conversions Summary").Range("C9", "AS176").Formula
    End With

    I managed to use the same code to copy & paste data from another closed workbook without any errors. Should there be any difference when copying the data from xlsx vs xlsm?
    Last edited by persistent83; 04-24-2013 at 05:42 AM. Reason: Need Help

  2. #2
    Registered User
    Join Date
    04-24-2013
    Location
    Perth, Australia
    MS-Off Ver
    Excel 2010
    Posts
    2

    Re: Getting data from closed workbook using VBA code

    This is the code that I used to copy paste data from another closed workbook which worked fine without any errors.

    Sub GetDataFromClosedWorkbook()
    Dim wb As Workbook
    Application.ScreenUpdating = False
    Set wb = Workbooks.Open("T:\Data\Scorecard.xlsx", True, True)
    With ThisWorkbook.Worksheets("Data")
    .Range("A4", "DQ502").Formula = wb.Worksheets("Final Summary").Range("A3", "DQ501").Formula
    End With
    wb.Close False
    Set wb = Nothing
    Application.ScreenUpdating = True
    End Sub
    Last edited by persistent83; 04-24-2013 at 05:34 AM.

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Tags for this Thread

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