Search the web
Sign In
New User? Sign Up
qtp_emos · EMOS Framework for QTP
? Already a member? Sign in to Yahoo!

Yahoo! Groups Tips

Did you know...
Want to share photos of your group with the world? Add a group photo to Flickr.

Best of Y! Groups

   Check them out and nominate your group.
Having problems with message search? Fill out this form to ensure your group is one of the first to be migrated to the new message search system.

Messages

  Messages Help
Advanced
Importing a text file data into an excel file   Message List  
Reply | Forward Message #181 of 246 |
Hi,

I have a requirement of importing a text file which contains data in
tabular format into excel. I am able to do the same with below code.
Does anyone has a better alternative as I am facing issues of
sometimes the data moving into different columns resulting in wrong
data with the below code :


columnheadings=Array("Item Name","Buyer","Qty")
startrow=18
Call UdfImporttxtFiletoExcel
("c:\recontextfile.txt","c:\recontextfile.xls",columnheadings,startro
w)
Public function UdfImporttxtFiletoExcel
(txtFilename,excelFilename,columnheadings,startrow)
Set ExcelObj = CreateObject("Excel.Application")
ExcelObj.DisplayAlerts = False
ExcelObj.Workbooks.Add
ExcelObj.Visible = true
ExcelObj.Workbooks.OpenText txtFilename,,startrow,1
ExcelObj.Columns("A:A").select
ExcelObj.selection.TextToColumns,2
xlcolum=1
For arRow=0 to ubound(columnheadings)
ExcelObj.Cells(1,xlcolum) = columnheadings
(arRow)
xlcolum=xlcolum+1
next
Set NewSheet = ExcelObj.Sheets.Item(1)
ExcelObj.Rows("1:1").Select
ExcelObj.Selection.Font.Bold=True
ExcelObj.Rows("1:65000").Select
ExcelObj.Selection.Font.size=8
ExcelObj.ActiveWorkbook.SaveAs excelFilename,1
ExcelObj.ActiveWorkbook.close
Set ExcelObj = Nothing
end function


e.g. My text file contains
Item Name Buyer Qty
-------------- ---------- ----------
15-3292-01 Yellig, Thomas 25
15-3292-01 Yellig, Thomas john 50

Sometimes the function will force the Buyer name : Yellig, Thomas
john to trespass into the 3rd column in excel so the Qty will be
pasted in 4th column.

Has anyone got a workaround for importing txt files into xls or a
resolution for above issue?

Regards,
Ganesh




Thu Jul 12, 2007 12:44 pm

mgkganesh
Offline Offline
Send Email Send Email

Forward
Message #181 of 246 |
Expand Messages Author Sort by Date

Hi, I have a requirement of importing a text file which contains data in tabular format into excel. I am able to do the same with below code. Does anyone has a...
Ganesh
mgkganesh
Offline Send Email
Jul 12, 2007
12:45 pm
Advanced

Copyright © 2009 Yahoo! Inc. All rights reserved.
Privacy Policy - Terms of Service - Guidelines - Help