Thursday, 13 September 2012

Excel VBA Macro to Import a Text File

Excel VBA Macro to Import a Text File
 Sub MAC1()
 Dim a As Integer
 Dim b As Integer
With ActiveSheet.QueryTables.ADD(Connection:= _
    "TEXT;C:\Documents and Settings\Administrator\Desktop\code1.txt" _
    , Destination:=Cells(1, 1))
    .Refresh BackgroundQuery:=True
 End With
'Loop to Join all cells data of first column  into one cell

For a = 1 To 100
Cells(1, 1) = Cells(1, 1) & Cells(a, 1)
Next a
For b = 2 To 100
Cells(b, 1).Clear
Next b

'Pull out desired string from a cell having text 
Cells(4, 2) = Mid(Cells(1, 1), InStr(Cells(1, 1), "True") - 10, 30)

End Sub

No comments:

Post a Comment

Hi User, Thank You for Visiting My Blog. Please Post Your Feedback/Comments/Query.

Subscribe to Blog Posts by Email

ExcelKingdom-Popular Posts

ExcelKingdom-Random Posts