VBA help needed. Need code to close workzone after I have copied data from it and pasted it to another WB

Joined
Jan 5, 2012
Messages
38
Hello Forum. I would like to ask for help with my VBA code. I am working with 2 csv files. After copying some information (data) for one csv file and then pasting it to another file, i want to close the first file.

Currently, after i copy from file one and then pasting this information to file 2 and operating some vba sequence on file 2 and after completion, file 2 is saved and closed and file 1 remained opened.

I need to ask for help to close file 1 without saving and without a prompt to user. Basically, I only need information from file 1. I don't need to alter anything there. Can anyone help?


Code:
Sub TEST()
'
' TEST Macro
Dim strPath As String, strFile As String
Dim strFileK As String

Dim wbSource As Workbook
strPath = ActiveWorkbook.Path & "\"
    
    strFile = Dir(strPath & "*PROCESSED.csv")
    strFileK = Dir(strPath & "Report.xls")

Set w = ActiveWorkbook
Application.ScreenUpdating = False
    Columns("C:D").Select
Selection.ClearContents
Range("E1").Select
    Range(Selection, Selection.End(xlToRight)).Select
Selection.Copy
Range("C1").Select
    Selection.PasteSpecial Paste:=xlPasteAll, Operation:=xlNone, SkipBlanks:= _
        False, Transpose:=True
Columns("E:HZ").Select
Selection.Delete Shift:=xlToLeft

If Len(strFile) Then

Workbooks.Open (strPath & strFile)
  
  Else
        MsgBox " I am unable to find your PROCESSED.csv", , "File Not Found"
    ActiveWorkbook.Close False
    Exit Sub
    End If


    Sheets(1).Select
    Range("A1").Select
    Selection.ClearContents
    Range("D1").Select
    Selection.ClearContents
Range("A1").Select
    Selection.ClearContents
    Range("D1").Select
    Selection.ClearContents
    Columns("A:A").Select
    ActiveSheet.Range("$A$1:$A$11000").RemoveDuplicates Columns:=1, Header:=xlNo
    Columns("D:D").Select
    ActiveSheet.Range("$D$1:$D$11000").RemoveDuplicates Columns:=1, Header:=xlNo
    Range("A:A,D:D").Select
    Range("D1").Activate
    Selection.Copy

w.Activate
Range("G1").Select
ActiveSheet.Paste
Cells.Select
    Selection.FormatConditions.AddUniqueValues
    Selection.FormatConditions(Selection.FormatConditions.Count).SetFirstPriority
    Selection.FormatConditions(1).DupeUnique = xlDuplicate
    With Selection.FormatConditions(1).Interior
        .PatternColorIndex = xlAutomatic
        .Color = 49407
        .TintAndShade = 0
    End With
    Selection.FormatConditions(1).StopIfTrue = False
Columns("A:K").Select
    Columns("A:K").EntireColumn.AutoFit
Range("A1").Select

Application.ScreenUpdating = True

 ActiveWorkbook.SaveAs (strPath & "Report.xlsm"), FileFormat:=52
        
MsgBox ("The operation has been completed!" & vbNewLine & "Check!." & vbNewLine & vbNewLine & "Check next column!"), vbInformation + vbOKOnly, "Audit finished"
 
        
End Sub

How do i close that processed.csv?

where should i add the code?
 

Excel Facts

Why are there 1,048,576 rows in Excel?
The Excel team increased the size of the grid in 2007. There are 2^20 rows and 2^14 columns for a total of 17 billion cells.

Forum statistics

Threads
1,203,460
Messages
6,055,554
Members
444,796
Latest member
18ecooley

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