Macro no longer working after downgrade from office 2015 to 2010

BBG Metalmeccanica 1 Reputation point
2021-10-15T13:53:17.25+00:00

Good morning
I wanted to show you this macro that I used and it worked fine until I installed office 2010. First on the pc there was office 2016 installed. I also posted the code, the macro copies a sheet from an excel file and pastes it into another file excel and appends the copy to a sheet.
I can't understand why it doesn't work anymore. If anybody please have any ideas and want to help me.
Greetings and thanks

Sub AccodaFogliKitamura()

  Dim wbk1 As Workbook
  Dim wbk2 As Workbook
  Dim Sheet1 As Worksheet
  Dim Sheet2 As Worksheet
  Dim lriga, lriga2 As Long
  Dim rng1, rng2 As Range


  Application.ScreenUpdating = False


   Set wbk1 = Workbooks.Open("C:\Users\fabri\Documents\BBG\BBG-PROGRAMMAZIONE-LAVORO.xlsm")


   Set Sheet1 = wbk1.Sheets("Kitamura")

   With Sheet1
    lriga = .Range("A" & .Rows.Count).End(xlUp).Row
   End With

   Set wbk2 = Workbooks.Open("C:\Users\fabri\Documents\BBG\CERCA-DATA-LEVIEN-EURO.xlsm")


   Set Sheet2 = wbk2.Sheets("FogliAccodati")

   With Sheet2
    lriga2 = .Range("A" & .Rows.Count).End(xlUp).Row
   End With



   Sheet1.Range("A2 : K" & lriga).Copy _
   Destination:=Sheet2.Range("A" & lriga2)

   Application.ScreenUpdating = True

End Sub
0 comments No comments
{count} votes

3 answers

Sort by: Most helpful
  1. Tom van Stiphout 1,621 Reputation points MVP
    2021-10-15T15:12:42.92+00:00

    "it doesn't work" is not very descriptive. What is it supposed to do and does not do anymore?
    What happens if you set a breakpoint at the top, and step through the code?

    0 comments No comments

  2. BBG Metalmeccanica 1 Reputation point
    2021-10-18T08:07:00.13+00:00

    Yes, sorry. I attach a screenshot of the debug, it practically gets to the set of the first sheet and then exits the routine. Maybe it's the two sets of workbooks one after the other that give the error. I can't get out of it.
    Thank you very much for your interest
    Fabrizio141331-cattura.png

    0 comments No comments

  3. Tom van Stiphout 1,621 Reputation points MVP
    2021-10-18T14:58:17.26+00:00

    I think you need to close the first workbook before you open the next.

    0 comments No comments