Brandonfromsingapore
New Member
- 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?
How do i close that processed.csv?
where should i add the code?
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?