Error code 1004

Girox8

New Member
Joined
Jan 29, 2017
Messages
2
Hi,

I used an existing macro that should be working but it doesn't anymore neither does the one below.

Code:
        Dim x As Integer
        Dim i As Integer
        
        x = 1
        For i = 0 To 15
        
        Range("c4").Value = (x + i)
                    
        Sheets("feuil1").Select
        PathName = Range("D3").Value
        Filename = Range("D4").Value
        TabName = Range("D5").Value
        ControlFile = ActiveWorkbook.Name
        Workbooks.Open Filename:=PathName & Filename
        ActiveSheet.Name = TabName
        Sheets(TabName).Copy After:=Workbooks(ControlFile).Sheets(1)
        Windows(Filename).Activate
        ActiveWorkbook.Close SaveChanges:=False
        Windows(ControlFile).Activate
        
        Sheets("feuil1").Select
        TabName2 = Range("D6").Value
        Workbooks.Open Filename:=PathName & Filename
        ActiveSheet.Name = TabName2
        Sheets(TabName2).Copy After:=Workbooks(ControlFile).Sheets(1)
        Windows(Filename).Activate
        ActiveWorkbook.Close SaveChanges:=False
        Windows(ControlFile).Activate
        Sheets("feuil1").Select
        
        Next i
        
        Range("c4").Value = 0
    
    End Sub

I know the second part is probably incorrect, but the first one is from the existing code so it should be working fine.

What is the problem?

Thanks for reading!
 
Last edited by a moderator:

Excel Facts

When did Power Query debut in Excel?
Although it was an add-in in Excel 2010 & Excel 2013, Power Query became a part of Excel in 2016, in Data, Get & Transform Data.

Forum statistics

Threads
1,216,524
Messages
6,131,176
Members
449,629
Latest member
Mjereza

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top