PDA

View Full Version : Macros to Import Keyword file



prashanth15
06-28-2013, 10:48 AM
:bug: Hi All,
i need a keyword fil to be imported to excel file. Key word file will look like below:
@name="reddy",@ssn="1223456789",@phone="123456789"

can anyone help me in creating macrose for this.

thanks for your help.

patel
06-30-2013, 01:12 AM
it's not clear for me

Kenneth Hobs
07-01-2013, 06:27 AM
Welcome to the forum!

Zip and attach the example TXT and XLSM files. Manually markup the XLSM file with what you expect imported from TXT file.

Paul_Hossler
07-01-2013, 09:45 AM
I used a very simple keywords file as a test and a simple macro to get you started



@name="reddy",@ssn="1223456789",@phone="123456789"
@name="reddy1",@ssn="223456789",@phone="12345678"
@name="reddy2",@ssn="23456789",@phone="1234567"
@name="reddy3",@ssn="3456789",@phone="123456"
@name="reddy4",@ssn="456789",@phone="123456"
@name="reddy5",@ssn="56789",@phone="12345"



Option Explicit

Sub ReadKeys()
Dim sLine As String, sEntry As String
Dim sFilename As Variant
Dim iFile As Long, iOut As Long, i As Long, iEquals As Long

Dim vSplit As Variant

sFilename = Application.GetOpenFilename
If sFilename = False Then Exit Sub


iOut = 1

iFile = FreeFile

Open sFilename For Input As #iFile

Do While Not EOF(iFile)

Line Input #iFile, sLine

sLine = Replace(sLine, ",@", vbTab)
If Left(sLine, 1) = "@" Then sLine = Right(sLine, Len(sLine) - 1)
sLine = Replace(sLine, """", vbNullString)
vSplit = Split(sLine, vbTab)

For i = LBound(vSplit) To UBound(vSplit)
sEntry = Trim(vSplit(i))
iEquals = InStr(sEntry, "=")

If iEquals > 0 Then
ActiveSheet.Cells(iOut, i + 1).Value = Right(sEntry, Len(sEntry) - iEquals)
End If
Next i

iOut = iOut + 1
Loop
Close #iFile
End Sub


Paul


Edit:

Ken's right -- a sample before and after file would be useful