Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,101
Default import txt file macro

I am trying to write a macro that will be in file1.xls. I want to
import/open a text file and that to be the only worksheet in my file1.xls
workbook. I can't delete all worksheets in a workbook so I run the macro,
open the text file, copy the worksheet to file1.xls, delete "Sheet1" from
file1.xls -- when I do this I get a prompt that says something like there may
be data in the worksheet are you sure you want to delete it?

How do I avoid the prompt? or is there a better way to import to an empty
workbook? --- My code is at the bottom

Thanks for any help
Mike

__________________________________________
Sub ImportDataFile()

'Opens Input form and takes user input
Call GetUserInput

'Open file using the input of runname as file to open
Call ImportFile

End Sub


Sub ImportFile()
ChDir "C:\Documents and Settings\drewermr.LABS\Desktop\EPD\New from Judi"
Workbooks.OpenText Filename:= _
"C:\Documents and Settings\drewermr.LABS\Desktop\EPD\New from Judi\"
& UserInput.txtRunName.Text & ".txt" _
, Origin:=437, StartRow:=1, DataType:=xlDelimited, TextQualifier:= _
xlDoubleQuote, ConsecutiveDelimiter:=False, Tab:=True,
Semicolon:=False, _
Comma:=False, Space:=False, Other:=False, FieldInfo:=Array(Array(1,
1), _
Array(2, 1), Array(3, 1), Array(4, 1), Array(5, 1), Array(6, 1)),
TrailingMinusNumbers _
:=True

' Sheets("Sheet1").Select
Windows(UserInput.txtRunName.Text & ".txt").Activate
Sheets(UserInput.txtRunName.Text).Select
Sheets(UserInput.txtRunName.Text).Copy
Befo=Workbooks("mikes.xls").Sheets(1)
Sheets("Sheet1").Select
ActiveWindow.SelectedSheets.Delete


End Sub

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default import txt file macro

One way is to use code like this sample code at Chip Pearson's site:

http://www.cpearson.com/excel/imptext.htm import/export text files


you could also modify your code

Application.DisplayAlerts = False
ActiveWindow.SelectedSheets.Delete
Application.displayAlerts = True


--
Regards,
Tom Ogilvy


"Mike" wrote in message
...
I am trying to write a macro that will be in file1.xls. I want to
import/open a text file and that to be the only worksheet in my file1.xls
workbook. I can't delete all worksheets in a workbook so I run the macro,
open the text file, copy the worksheet to file1.xls, delete "Sheet1" from
file1.xls -- when I do this I get a prompt that says something like there

may
be data in the worksheet are you sure you want to delete it?

How do I avoid the prompt? or is there a better way to import to an empty
workbook? --- My code is at the bottom

Thanks for any help
Mike

__________________________________________
Sub ImportDataFile()

'Opens Input form and takes user input
Call GetUserInput

'Open file using the input of runname as file to open
Call ImportFile

End Sub


Sub ImportFile()
ChDir "C:\Documents and Settings\drewermr.LABS\Desktop\EPD\New from Judi"
Workbooks.OpenText Filename:= _
"C:\Documents and Settings\drewermr.LABS\Desktop\EPD\New from

Judi\"
& UserInput.txtRunName.Text & ".txt" _
, Origin:=437, StartRow:=1, DataType:=xlDelimited, TextQualifier:=

_
xlDoubleQuote, ConsecutiveDelimiter:=False, Tab:=True,
Semicolon:=False, _
Comma:=False, Space:=False, Other:=False,

FieldInfo:=Array(Array(1,
1), _
Array(2, 1), Array(3, 1), Array(4, 1), Array(5, 1), Array(6, 1)),
TrailingMinusNumbers _
:=True

' Sheets("Sheet1").Select
Windows(UserInput.txtRunName.Text & ".txt").Activate
Sheets(UserInput.txtRunName.Text).Select
Sheets(UserInput.txtRunName.Text).Copy
Befo=Workbooks("mikes.xls").Sheets(1)
Sheets("Sheet1").Select
ActiveWindow.SelectedSheets.Delete


End Sub



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,101
Default import txt file macro

Thanks for the tip.

Mike

"Tom Ogilvy" wrote:

One way is to use code like this sample code at Chip Pearson's site:

http://www.cpearson.com/excel/imptext.htm import/export text files


you could also modify your code

Application.DisplayAlerts = False
ActiveWindow.SelectedSheets.Delete
Application.displayAlerts = True


--
Regards,
Tom Ogilvy


"Mike" wrote in message
...
I am trying to write a macro that will be in file1.xls. I want to
import/open a text file and that to be the only worksheet in my file1.xls
workbook. I can't delete all worksheets in a workbook so I run the macro,
open the text file, copy the worksheet to file1.xls, delete "Sheet1" from
file1.xls -- when I do this I get a prompt that says something like there

may
be data in the worksheet are you sure you want to delete it?

How do I avoid the prompt? or is there a better way to import to an empty
workbook? --- My code is at the bottom

Thanks for any help
Mike

__________________________________________
Sub ImportDataFile()

'Opens Input form and takes user input
Call GetUserInput

'Open file using the input of runname as file to open
Call ImportFile

End Sub


Sub ImportFile()
ChDir "C:\Documents and Settings\drewermr.LABS\Desktop\EPD\New from Judi"
Workbooks.OpenText Filename:= _
"C:\Documents and Settings\drewermr.LABS\Desktop\EPD\New from

Judi\"
& UserInput.txtRunName.Text & ".txt" _
, Origin:=437, StartRow:=1, DataType:=xlDelimited, TextQualifier:=

_
xlDoubleQuote, ConsecutiveDelimiter:=False, Tab:=True,
Semicolon:=False, _
Comma:=False, Space:=False, Other:=False,

FieldInfo:=Array(Array(1,
1), _
Array(2, 1), Array(3, 1), Array(4, 1), Array(5, 1), Array(6, 1)),
TrailingMinusNumbers _
:=True

' Sheets("Sheet1").Select
Windows(UserInput.txtRunName.Text & ".txt").Activate
Sheets(UserInput.txtRunName.Text).Select
Sheets(UserInput.txtRunName.Text).Copy
Befo=Workbooks("mikes.xls").Sheets(1)
Sheets("Sheet1").Select
ActiveWindow.SelectedSheets.Delete


End Sub




Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
macro-import another xls file puiuluipui Excel Discussion (Misc queries) 9 April 1st 10 06:48 PM
Error in large file import macro Scott Calkins via OfficeKB.com Excel Programming 8 September 30th 05 12:39 PM
macro for import of csv .txt file? Ryan Cain Excel Programming 1 August 5th 05 05:43 AM
macro to import file (help with a piece of code) uriel78 Excel Programming 4 March 12th 05 08:36 AM
macro which import alfa*.txt file, how to ? ss_era Excel Programming 1 August 24th 04 01:47 PM


All times are GMT +1. The time now is 10:21 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"