Problem with zipfiles

ryan8200

Active Member
Joined
Aug 21, 2011
Messages
357
I have downloaded 2 zip files and want to insert the csv files inside zip files to my current worksheet. I want the first csv file from 1st downloaded zip file to rename as Sheet_A and Sheet_B for csv files from 2nd downloaded zip files. When I try to add to my current workbook, csv from 2nd downloaded zip tend to be renamed as Sheet_1. Kindly help on this.
VBA Code:
Sub Addcsv()
Dim Path As String, Filename As String
Dim Sheet As Worksheet
Path = "C:\Users\My\Downloads\"
Filename = Dir(Path & "Report*")

' Disable Screen Updating is used to stop screen flickering and Disable Events is used to avoid interrupted dialog boxes / popups
With Application
    .ScreenUpdating = False
    .EnableEvents = False
End With

  Do While Filename <> ""
  
  Workbooks.Open Filename:=Path & Filename, ReadOnly:=True
     For Each Sheet In ActiveWorkbook.Sheets
     Sheet.Copy after:=ThisWorkbook.Sheets(2)
  Next Sheet
     Workbooks(Filename).Close
     Filename = Dir()
  Loop
  ' Resume Screen Updating and Events
  With Application
        .ScreenUpdating = True
        .EnableEvents = True
  End With

  Sheets(2).Name = "Sheet_A"
  Sheets(3).Name = "Sheet_B"
 

Excel Facts

Excel motto
Not everything I do at work revolves around Excel. Only the fun parts.
CSV files are just text files - you can try opening one in Notepad to see what I mean. Accordingly, they don't have 'sheets' (as such), like an Excel XLSX does. You would need to save the file as an Excel workbook - either XLS, XLSX, XLSB, XLSM etc.
 
Upvote 0

Forum statistics

Threads
1,215,513
Messages
6,125,256
Members
449,219
Latest member
daynle

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