Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Microsoft Office > Excel VBA > Excel VBA
Excel VBA Discuss using VBA for Excel programming.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Excel VBA section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
Old April 29th, 2004, 01:52 AM
Registered User
Join Date: Apr 2004
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
Default Excel IMport Text Help!!

I need help on the coding. I am wondering why i canot import text field into my excel worksheet. Here is my coding. Is it somehitng wrong with my code or what?? Please help me out..thank very much

sub importfile()
workbooks.opentext _
  fileName:="C:\ExcelVBA\Nov2002.txt", _
  origin:=xlWindows, _
  StartRow:=4, _
  DataType:=xlFixedWidth, _
  FieldInfo:=Array(Array(0, 1), Array(8, 1), _
         Array(20, 1), Array(27, 1), Array(42, 1), _
         Array(49, 1)), _
with ActiveWindow
       .width = 452.25
       .Height = 254.25
end with


Sheets("Nov2002").Move _
Before:=Workbooks("Chapter02.xls"), Sheets(1)
End Sub

Old April 29th, 2004, 03:07 AM
Friend of Wrox
Join Date: Jun 2003
Posts: 173
Thanks: 0
Thanked 3 Times in 3 Posts

This works for me:

Sub ImportFile()

    Workbooks.OpenText _
        Filename:=Application.GetOpenFilename("Text Files (*.txt), _
        *.txt"), _
        Origin:=xlWindows, StartRow:=4, DataType:=xlFixedWidth, _
        FieldInfo:=Array(Array(0, 1), Array(8, 1), Array(20, 1), _
        Array(27, 1), Array(42, 1), Array(49, 1))

' ' What is this doing?
' With ActiveWindow
' .Width = 452.25
' .Height = 254.25
' End With

    Sheets(ActiveSheet.Name).Move Before:=ThisWorkbook.Sheets(1)


End Sub
Old April 30th, 2004, 12:43 AM
Registered User
Join Date: Apr 2004
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts

thank you..but it's still didnot work for me. It was import a text file into excel sheet but i want to copy that sheet to my workbook that part is stll did not work at all..would you tell me how..
  When i immport text file into excel it will bring up new workbook and creat that file into worksheet's name but i want to copy this worksheet to my original workbook..
 coding was hightline this part...thank you for your help..

    Sheets(ActiveSheet.Name).Move Before:=ThisWorkbook.Sheets(1)


Similar Threads
Thread Thread Starter Forum Replies Last Post
Text Import- How to import the first 5 lines. nickzhang.zn Excel VBA 1 August 4th, 2007 05:06 PM
Import from Excel sheet to a text file zone Excel VBA 1 July 26th, 2007 10:34 AM
How to import data from text file? starnet SQL Server 2000 1 September 18th, 2006 06:56 AM
import data from text file to excel(VBA) topr Excel VBA 2 August 26th, 2004 11:36 PM
Excel text Import and VB Franck Excel VBA 0 January 8th, 2004 09:57 AM

Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.