Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Problems opening a text file using macro!

Hi all!

I've a quick question with respect to the short macro shown below.

Sub importfile()
Application.DisplayAlerts = False
MyFile = Application.GetOpenFilename("text files,*.txt")
Workbooks.OpenText FileName:=MyFile, _
Origin:=xlWindows, StartRow:=1,
DataType:=xlFixedWidth, FieldInfo:= _
Array(Array(0, 1), Array(11, 1), Array(20, 1))
ActiveWindow.WindowState = xlNormal
Sheets("MyFinal").Select
Sheets("MyFinal").Move Befo=Workbooks
("vtec.xls").Sheets(1)
End Sub


The browsed and selected *.txt file is assigned to the variabl
"MyFile".
However, I am unable to move it before the existing workbook '
tec.xls' and it is giving me error. A small error in the line:

Sheets("MyFinal").Select
Sheets("MyFinal").Move Befo=Workbooks("vtec.xls").Sheets(1)

I would appreciate any tips.
Thanks alot guys.

Regds,

Arun.
Vtec Corp

--
Message posted from http://www.ExcelForum.com

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 863
Default Problems opening a text file using macro!

Try opening the workbook manually, then turn on the macro recorder, then move
the sheet to the other workbook. The recorded code will give you the correct
syntax.


On Fri, 27 Aug 2004 14:04:04 -0500, aiyer
wrote:

Hi all!

I've a quick question with respect to the short macro shown below.

Sub importfile()
Application.DisplayAlerts = False
MyFile = Application.GetOpenFilename("text files,*.txt")
Workbooks.OpenText FileName:=MyFile, _
Origin:=xlWindows, StartRow:=1,
DataType:=xlFixedWidth, FieldInfo:= _
Array(Array(0, 1), Array(11, 1), Array(20, 1))
ActiveWindow.WindowState = xlNormal
Sheets("MyFinal").Select
Sheets("MyFinal").Move Befo=Workbooks
("vtec.xls").Sheets(1)
End Sub


The browsed and selected *.txt file is assigned to the variable
"MyFile".
However, I am unable to move it before the existing workbook 'V
tec.xls' and it is giving me error. A small error in the line:

Sheets("MyFinal").Select
Sheets("MyFinal").Move Befo=Workbooks("vtec.xls").Sheets(1)

I would appreciate any tips.
Thanks alot guys.

Regds,

Arun.
Vtec Corp.


---
Message posted from http://www.ExcelForum.com/


  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default Problems opening a text file using macro!

Your code runs fine for me if
a) I have vtec.xls open
b) the file I select to open is named MyFinal.txt

If you don't meet those two conditions, you will have problems. But since
you wrote it that way, you must be aware of that. If you want it to work
with any text file selected, then

Sub importfile()
Dim bk as Workbook
Application.DisplayAlerts = False
MyFile = Application.GetOpenFilename("text files,*.txt")
set bk = Workbooks.OpenText( Filename:=MyFile, _
Origin:=xlWindows, StartRow:=1, _
DataType:=xlFixedWidth, FieldInfo:= _
Array(Array(0, 1), Array(11, 1), Array(20, 1)))
bk.Sheets(1).Move Befo=Workbooks _
("vtec.xls").Sheets(1)
End Sub

--
Regards,
Tom Ogilvy


--
Regards,
Tom Ogilvy

"aiyer " wrote in message
...
Hi all!

I've a quick question with respect to the short macro shown below.

Sub importfile()
Application.DisplayAlerts = False
MyFile = Application.GetOpenFilename("text files,*.txt")
Workbooks.OpenText FileName:=MyFile, _
Origin:=xlWindows, StartRow:=1,
DataType:=xlFixedWidth, FieldInfo:= _
Array(Array(0, 1), Array(11, 1), Array(20, 1))
ActiveWindow.WindowState = xlNormal
Sheets("MyFinal").Select
Sheets("MyFinal").Move Befo=Workbooks
("vtec.xls").Sheets(1)
End Sub


The browsed and selected *.txt file is assigned to the variable
"MyFile".
However, I am unable to move it before the existing workbook 'V
tec.xls' and it is giving me error. A small error in the line:

Sheets("MyFinal").Select
Sheets("MyFinal").Move Befo=Workbooks("vtec.xls").Sheets(1)

I would appreciate any tips.
Thanks alot guys.

Regds,

Arun.
Vtec Corp.


---
Message posted from http://www.ExcelForum.com/



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 error opening text file Jim C Excel Discussion (Misc queries) 0 November 6th 09 04:05 PM
Problems opening file Russ Excel Discussion (Misc queries) 3 September 14th 06 04:51 PM
Opening text file in Excel through macro Ed[_9_] Excel Programming 0 October 7th 03 04:13 PM
Opening text file in Excel through macro Tom Ogilvy Excel Programming 0 October 7th 03 03:53 PM
Opening text file in Excel through macro shockley Excel Programming 0 October 7th 03 03:49 PM


All times are GMT +1. The time now is 08:28 AM.

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"