+ Reply to Thread
Results 1 to 10 of 10

Run-time error '1004' on closing workbook

Hybrid View

  1. #1
    Forum Contributor pipoliveira's Avatar
    Join Date
    08-09-2012
    Location
    Ireland
    MS-Off Ver
    Microsoft Office 365 ProPlus
    Posts
    368

    Run-time error '1004' on closing workbook

    Dear all,

    I hope you are all well.

    I am having the following error:

    Run-time error '1004'
    Select method of Range class failed

    This error is on the Workbook.Close event in red:

    Sub Update_Info_Analytics_Reg()
    
    Sheets("Registrations").Activate
    
    Application.ScreenUpdating = False 'prevents screen flashing through sheets during code
    
    Application.StatusBar = "Please wait ... Run Mobile copy in progress"
    
    'WorkBooks
    Dim iRowReg As Long
    Dim LR As Long
    Dim wbMaster As Workbook
    Dim wbAnalytics As Workbook
    
    'Setting Worksheets
    Dim wsMasterReg As Worksheet 'Master Value Map Registrations
    Dim wsAnalyticsReg As Worksheet 'Pilot Analytics
    
    'Setting Worksheets and Workbooks locations
    Set wbMaster = Workbooks("Pilot_Master_Dashboard.xlsm") 'Master
    Set wsMasterReg = wbMaster.Sheets("Registrations") 'Master Registrations page
    Set wbAnalytics = Workbooks.Open(Filename:="C:\Users\PIPO\Documents\Analytics_DashBoard.xlsm") 'Pilot Analytics file
    Set wsAnalyticsReg = wbAnalytics.Sheets("Nomination") 'Pilot Analytics Registrations Sheet
    
    wsMasterReg.Range("D13:I1000").ClearContents
    
    'Finds first empty row in Master's Registrations table
    iRowReg = wsMasterReg.Range("E" & Rows.Count).End(xlUp).Row + 1
    
    'Copy Registrations from Child (Analytics) to Master
    
    'Value Map
    wsAnalyticsReg.Range("AH13:AH732").Copy
    wsMasterReg.Cells(iRowReg, 4).PasteSpecial xlPasteValues
    'Customer Name
    wsAnalyticsReg.Range("D13:D732").Copy
    wsMasterReg.Cells(iRowReg, 5).PasteSpecial xlPasteValues
    'Customer Number
    wsAnalyticsReg.Range("E13:E732").Copy
    wsMasterReg.Cells(iRowReg, 6).PasteSpecial xlPasteValues
    'Country
    wsAnalyticsReg.Range("G13:G732").Copy
    wsMasterReg.Cells(iRowReg, 7).PasteSpecial xlPasteValues
    'Region
    wsAnalyticsReg.Range("H13:H732").Copy
    wsMasterReg.Cells(iRowReg, 8).PasteSpecial xlPasteValues
    'Dedicated ESA
    wsAnalyticsReg.Range("S13:S732").Copy
    wsMasterReg.Cells(iRowReg, 9).PasteSpecial xlPasteValues
    
    wsMasterReg.Activate
    
    Application.CutCopyMode = False
    
    wbAnalytics.Close False
    
    Set wbAnalytics = Nothing
    Set wsAnalyticsReg = Nothing
    Set wsMasterReg = Nothing
    
    Application.ScreenUpdating = True
    
    Application.StatusBar = ""
    
    Call Update_Info_BPI_Reg
    
    End Sub
    This code copy information from a "Child" document to a "Master".

    I have a similar Master file with the exact codes (from other files) and it works perfectly closing the "Child" files without any errors.

    Any ideas why on this code it gives me the error?

    Your assistance will be highly appreciated.

    Best regards,
    Filipe Oliveira

  2. #2
    Forum Contributor HerryMarkowitz's Avatar
    Join Date
    09-10-2012
    Location
    Europe
    MS-Off Ver
    Office 2021 - Win10
    Posts
    1,014

    Re: Run-time error '1004' on closing workbook

    If you want to close wbAnalytics workbook you should use following code;
    wbAnalytics.Close True
    If you dont want to close wbAnalytics workbook you dont need any code. So, you can delete that line.
    Sub DontForgetThese()
         If Your thread includes any code Then Please use code tags...
         If Your thread has been solved Then Please mark as solved...
         If Anybody has helped to you Then Please add reputation...
    End Sub

  3. #3
    Forum Contributor pipoliveira's Avatar
    Join Date
    08-09-2012
    Location
    Ireland
    MS-Off Ver
    Microsoft Office 365 ProPlus
    Posts
    368

    Re: Run-time error '1004' on closing workbook

    Hi Herry,
    Thanks for the reply.
    Your code is to close and save but I just want to close it without saving, that's why my code has "False".
    As mentioned, the same code works perfectly on other similar file but on this one I get that error code.
    Cheers,
    Filipe


    Sent from my iPhone using Tapatalk


    * If a reply solved or answered your query/question, you can add reputation to the person by clicking on the * Add Reputation
    * When question is resolved, please mark your thread as SOLVED


    Thanks and regards,
    Filipe Oliveira

  4. #4
    Forum Contributor HerryMarkowitz's Avatar
    Join Date
    09-10-2012
    Location
    Europe
    MS-Off Ver
    Office 2021 - Win10
    Posts
    1,014

    Re: Run-time error '1004' on closing workbook

    According the code you sent there is no changes workbook declaring wbAnalytics (C:\Users\PIPO\Documents\Analytics_DashBoard.xlsm).
    So, you dont need without saving thing.

    Do you want time saving?

  5. #5
    Forum Contributor pipoliveira's Avatar
    Join Date
    08-09-2012
    Location
    Ireland
    MS-Off Ver
    Microsoft Office 365 ProPlus
    Posts
    368

    Re: Run-time error '1004' on closing workbook

    Hi Henry,
    Thanks for the reply.
    Even without changes, I have VBA codes on the "Open" and "before closes" events, meaning, only opening that file and closing, Excel asks if I was to save the changes.
    The main issue here is the "run-time error" that I am trying to understand why he does not accept it.
    I even tried your code and the same error occurred.
    Best regards,
    Filipe


    Sent from my iPhone using Tapatalk

  6. #6
    Forum Contributor HerryMarkowitz's Avatar
    Join Date
    09-10-2012
    Location
    Europe
    MS-Off Ver
    Office 2021 - Win10
    Posts
    1,014

    Re: Run-time error '1004' on closing workbook

    Change this,
    wbAnalytics.Close False
    to this,
    wbAnalytics.Close savechanges:=False


    or,
    Workbooks("Analytics_DashBoard.xlsm").Close SaveChanges:=False
    Last edited by HerryMarkowitz; 10-19-2014 at 07:13 PM.

  7. #7
    Forum Contributor pipoliveira's Avatar
    Join Date
    08-09-2012
    Location
    Ireland
    MS-Off Ver
    Microsoft Office 365 ProPlus
    Posts
    368

    Re: Run-time error '1004' on closing workbook

    Hi Herry,
    Thanks for your reply and efforts.
    Unfortunately, I have the same errors again with your codes.
    There must be something giving that error as I have the same one (Different workbooks) and it works fine.
    Best regards,
    Filipe

  8. #8
    Forum Expert romperstomper's Avatar
    Join Date
    08-13-2008
    Location
    England
    MS-Off Ver
    365, varying versions/builds
    Posts
    22,009

    Re: Run-time error '1004' on closing workbook

    You haven't posted the code in the BeforeClose event of that file. However, since you're not saving it, there doesn't seem to be a lot of need to run any code in it, so perhaps you could just use:
    Application.Enableevents = False
    wbAnalytics.Close False
    Application.Enableevents = True
    Everyone who confuses correlation and causation ends up dead.

  9. #9
    Forum Contributor pipoliveira's Avatar
    Join Date
    08-09-2012
    Location
    Ireland
    MS-Off Ver
    Microsoft Office 365 ProPlus
    Posts
    368

    Re: Run-time error '1004' on closing workbook

    Hi romperstomper,

    You really hit the spot with the "Application.EnableEvents".

    Still don't understand what "events" were creating the Error but it solved it.

    Thanks a million once again.

    Really appreciated.

    Best regards,
    Filipe

  10. #10
    Forum Contributor HerryMarkowitz's Avatar
    Join Date
    09-10-2012
    Location
    Europe
    MS-Off Ver
    Office 2021 - Win10
    Posts
    1,014

    Re: Run-time error '1004' on closing workbook

    Dont forget sending us a reputation point.

+ 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. Misterious Run-time error 1004 on Workbook Open
    By bagullo in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 04-01-2014, 10:09 AM
  2. Run time error 1004 only immediately after opening protected workbook
    By JoeSkittles in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 04-25-2013, 11:02 AM
  3. Replies: 1
    Last Post: 09-16-2011, 05:59 AM
  4. Macro works in one workbook and not another - Run-Time Error 1004
    By vrobinson in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 06-10-2010, 07:30 PM
  5. Run-Time Error 1004 Shared Workbook
    By jmagdziarz in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 05-06-2005, 07:35 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