I have 2 different type of files. 1 is ".tsv" 2 is ".xlsx".
I want my macro (.xlsm) file to be in same folder where 2 different files (.tsv and .xlsx) are placed. I usually download them from some tools and normally they are placed in my default "Download" folder.
Problem 1: I want my macro file to read both format and copy paste data into single excel file. I am done with this problem. Code optimization is required.
Problem 2: I am currently assigning manual path to that folder and want macro to pick that folder path so that it can copy 2 extension files and proceed.
(Tried : ActiveWorkbook.Path
, didn't work).
Dim FPath As String, filename As String, FileExt1 As String, FileExt2 As
String
Sub GetSheets()
FPath = "C:\Users\dinekuma\Desktop\Dinesh KT\Macro New UI\"
FileExt1 = "*.tsv"
FileExt2 = "*.xlsx"
'ActiveWorkbook.Path
'"C:\Users\dinekuma\Desktop\Dinesh KT\Macro New UI\"
filename = Dir(FPath & FileExt1)
Application.ScreenUpdating = False
Application.DisplayAlerts = False
Do While filename <> ""
Workbooks.Open filename:=FPath & filename, ReadOnly:=True
For Each sheet In ActiveWorkbook.Sheets
sheet.Copy After:=ThisWorkbook.Sheets(1)
ActiveSheet.Name = Split(filename, ".")(0)
Next sheet
Workbooks(filename).Close
filename = Dir()
Loop
filename = Dir(FPath & FileExt2)
Application.ScreenUpdating = False
Application.DisplayAlerts = False
Do While filename <> ""
Workbooks.Open filename:=FPath & filename, ReadOnly:=True
For Each sheet In ActiveWorkbook.Sheets
sheet.Copy After:=ThisWorkbook.Sheets(1)
ActiveSheet.Name = Split(filename, ".")(0)
Next sheet
Workbooks(filename).Close
filename = Dir()
Loop
MsgBox ("Import Successful!")
End Sub
Help in code optimization and automatic path pick by active macro file.