Macro to change Directory to C:\Downloads

howard

Well-known Member
Joined
Jun 26, 2006
Messages
6,561
Office Version
  1. 2021
Platform
  1. Windows
I have the folowing macro to open a CSV file and clear data in specific columns

The worbook that the macro resides in is in folder C:\My Documents


It would be appreciated if my code can be amended so that folder C:\Downloads is selected as the the CSV file has been downloaded in this folder

Code:
 Sub Open_911810_CSV()
Dim ws As Worksheet, File As String
File = Dir(ThisWorkbook.Path & "\*911810*.csv")
Set ws = Workbooks.Open(File).ActiveSheet
ActiveSheet.UsedRange.Columns("A:D").Offset(1).Clear
End Sub


Your assistance in this regard is most appreciated
 

Excel Facts

Waterfall charts in Excel?
Office 365 customers have access to Waterfall charts since late 2016. They were added to Excel 2019.
HTH
VBA Code:
Sub Open_911810_CSV()
    Dim ws As Workbook, File As String
    File = Dir("E:\Downloads" & "\*911810*.csv")
    Set ws = Workbooks.Open("E:\Downloads\" & File)
    ActiveSheet.UsedRange.Columns("A:D").Offset(1).Clear
End Sub
 
Upvote 0
Solution
I believe you will prefer this code.
Note that the code below will change your files "*911810*.csv" permanently.
You may backup files before running the macro.
VBA Code:
Sub Open_911810_CSV()
    Dim ws As Workbook, File As String
    File = Dir("C:\Downloads" & "\*911810*.csv")
    Do
        Set ws = Workbooks.Open("C:\Downloads\" & File)
        ActiveSheet.UsedRange.Columns("A:D").Offset(1).Clear
        ws.Close True
        File = Dir()
    Loop Until File = ""
End Sub
 
Upvote 0

Forum statistics

Threads
1,214,947
Messages
6,122,413
Members
449,082
Latest member
tish101

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