Results 1 to 2 of 2

Runtime error 1004 Application defined or object defined error

Threaded View

detcityced Runtime error 1004... 02-06-2018, 03:48 PM
Leith Ross Re: Runtime error 1004... 02-06-2018, 03:56 PM
  1. #1
    Registered User
    Join Date
    02-06-2018
    Location
    USA
    MS-Off Ver
    2016
    Posts
    1

    Runtime error 1004 Application defined or object defined error

    I dont know why i am having a lapse in brainwave activity but I cannot figure how to set the variable source worksheet = to the workbook source 1st sheet. I am looking to go into a named file folder and extract data from variable named file folders that each contain .xls files and copy and paste all copied data to the same new worksheet. My code breaks down and throws an error at the same location. If anyone can advise how to reference the first sheet using the set property that would be greatly beneficial. Below is a snippet of my code and the last line is where it breaks
    Sub collatefiles()
    
        Dim strDirContainingFiles As String, strFile As String, _
        strFilePath As String
        Dim wbkDst As Workbook, wbkSrc As Workbook
        Dim wksDst As Worksheet, wksSrc As Worksheet
        Dim lngIdx As Long, lngSrcLastRow As Long, _
            lngSrcLastCol As Long, lngDstLastRow As Long, _
            lngDstLastCol As Long, lngDstFirstFileRow As Long
        Dim rngSrc As Range, rngDst As Range, rngFile As Range
        Dim colFileNames As Collection
        Set colFileNames = New Collection
    
    'Set references up-front
    strDirContainingFiles = "Z:\Manufacturing\SensorRepo\2468\TestResults\AATF\"
    Set wbkDst = Workbooks.Add
    Set wksDst = wbkDst.ActiveSheet
    
    strFile = Dir(strDirContainingFiles & "*.xls")
    Do While Len(strFile) > 0
        colFileNames.Add Item:=strFile
        strFile = Dir
    Loop
    
    'Now we start looping through each source file and copy data
    'to our destination sheet
    
    For lngIdx = 1 To colFileNames.Count
    
        'Assign the file path
        strFilePath = strDirContainingFiles & colFileNames(lngIdx)
    
        'Open the workbook and store a reference to the data sheet
        Set wbkSrc = Workbooks.Open(strFilePath)
        Set wksSrc = wbkSrc.Sheets(1)
    Last edited by detcityced; 02-06-2018 at 04:00 PM. Reason: Added Code Tags

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. Runtime error 1004 application-defined object-defined
    By stevoDE in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 06-14-2017, 09:58 AM
  2. Replies: 5
    Last Post: 08-19-2015, 07:10 PM
  3. Replies: 0
    Last Post: 05-14-2012, 11:59 PM
  4. Runtime error 1004 application defined or object defined error
    By Wyliecody in forum Excel Programming / VBA / Macros
    Replies: 8
    Last Post: 02-03-2012, 12:38 PM
  5. Runtime error '1004' Application-defined or object-defined error Comment
    By Willer in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 11-17-2011, 03:02 PM
  6. [SOLVED] RE: Runtime error 1004- application defined or object defined erro
    By Novice in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 02-06-2006, 05:40 PM
  7. RE: Runtime error 1004- application defined or object defined erro
    By Jim Thomlinson in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 02-06-2006, 05:35 PM

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