Try

Workbooks.OpenText Filename:=fldpth & fname, _
Origin:=xlWindows, StartRow:=1, DataType:=xlFixedWidth, FieldInfo:= _
Array(0, 2), TrailingMinusNumbers:=True

On Mon, Sep 12, 2011 at 6:40 PM, mrinal saha <mris...@gmail.com> wrote:

>   Hey Folks,,
>
> I have figured out a code to match the text file with excel sheet name.but
> not able to open thetext file. Error in red line.
>
> I want to open without using get openfilename.
>
> Sub Read_text_File()
> Dim fso, fld, fil As Object
> Dim fldpth As String
>
> fldpth = "C:\Documents and Settings\287940\Desktop\Test Macros1\VBA
> Proj\Amlesh - Naveen\PDF\Page Center Reports"
> Set fso = CreateObject("scripting.filesystemobject")
> Set fld = fso.getfolder(fldpth)
> For Each fil In fld.Files
> fname = fil.Name
>
> For i = 1 To Sheets.Count
>
> If ActiveWorkbook.Sheets(i).Name = Left(fname, InStr(fname, ".") - 1) Then
> Workbooks.OpenText Filename:="fldpth & fname" & strng & ".txt", _
> Origin:=xlWindows, StartRow:=1, DataType:=xlFixedWidth, FieldInfo:= _
> Array(0, 2), TrailingMinusNumbers:=True
> End If
> Next i
> Next fil
> End Sub
>
> Thanks,
> Mrinal
>
>
> --
>
> ----------------------------------------------------------------------------------
> Some important links for excel users:
> 1. Follow us on TWITTER for tips tricks and links :
> http://twitter.com/exceldailytip
> 2. Join our LinkedIN group @ http://www.linkedin.com/groups?gid=1871310
> 3. Excel tutorials at http://www.excel-macros.blogspot.com
> 4. Learn VBA Macros at http://www.quickvba.blogspot.com
> 5. Excel Tips and Tricks at http://exceldailytip.blogspot.com
>
> To post to this group, send email to excel-macros@googlegroups.com
>
> <><><><><><><><><><><><><><><><><><><><><><>
> Like our page on facebook , Just follow below link
> http://www.facebook.com/discussexcel
>



-- 
Sam Mathai Chacko

-- 
----------------------------------------------------------------------------------
Some important links for excel users:
1. Follow us on TWITTER for tips tricks and links : 
http://twitter.com/exceldailytip
2. Join our LinkedIN group @ http://www.linkedin.com/groups?gid=1871310
3. Excel tutorials at http://www.excel-macros.blogspot.com
4. Learn VBA Macros at http://www.quickvba.blogspot.com
5. Excel Tips and Tricks at http://exceldailytip.blogspot.com
 
To post to this group, send email to excel-macros@googlegroups.com

<><><><><><><><><><><><><><><><><><><><><><>
Like our page on facebook , Just follow below link
http://www.facebook.com/discussexcel

Reply via email to