ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Problems opening a text file using macro! (https://www.excelbanter.com/excel-programming/308240-problems-opening-text-file-using-macro.html)

aiyer[_50_]

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


Myrna Larson

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/



Tom Ogilvy

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/





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

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com