Hi Friends,
Need some help on below, i am new to VBA programming & i don't know how to get this correct.I tried myself since last 3/4 days but not resloved yet.
I have one excel file contains 3 sheets, outof that 1 sheets contains the data which is linked to others 2 sheets. Data comes from csv file. I want to import the lastest csv file from specific location into same sheet on daily basis (overwriting the exisiting data). Here is my code.
Code:
Sub unhide()
Dim ws As Worksheet
For Each ws In ThisWorkbook.Sheets
If ws.Name = "DATA" Then
ws.Visible = xlSheetVisible
End If
Next ws
End Sub
Sub DeleteRows()
Dim ws As Worksheet, lRow As Long
Set ws = Worksheets("DATA")
lRow = ws.Range("A65536").End(xlUp).Row
ws.Rows("1:" & lRow).Delete Shift:=xlUp
Set ws = Nothing
End Sub
Sub Home()
Application.Goto Sheets("DATA").Range("A1")
Application.SendKeys ("^{Home}")
End Sub
Sub LoadFromFile()
Dim fileName As String, folder As String
folder = "D:\temp\Summary_Report_*.csv" '=>Note (* means date)
ActiveCell.Offset(0, 0).Range("A1").Select
With ActiveSheet.QueryTables _
.Add(Connection:="TEXT;" & folder, Destination:=ActiveCell)
.Parent.Name = "DATA"
.FieldNames = True
.RowNumbers = False
.FillAdjacentFormulas = True
.PreserveFormatting = True
.RefreshOnFileOpen = False
.RefreshStyle = xlInsertDeleteCells
.SavePassword = False
.SaveData = True
.AdjustColumnWidth = True
.RefreshPeriod = 0
.TextFilePromptOnRefresh = False
.TextFilePlatform = 850
.TextFileStartRow = 1
.TextFileParseType = xlDelimited
.TextFileTextQualifier = xlTextQualifierDoubleQuote
.TextFileConsecutiveDelimiter = False
.TextFileTabDelimiter = False
.TextFileSemicolonDelimiter = False
.TextFileCommaDelimiter = True
.TextFileSpaceDelimiter = False
.TextFileColumnDataTypes = Array(1, 1, 1, 1)
.TextFileTrailingMinusNumbers = True
.Refresh BackgroundQuery:=False
End With
End Sub
Sub hide()
Dim ws As Worksheet
For Each ws In ThisWorkbook.Sheets
If ws.Name = "DATA" Then
ws.Visible = xlSheetHidden
End If
Next ws
End Sub