Home |
Search |
Today's Posts |
#1
Posted to microsoft.public.excel.programming
|
|||
|
|||
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
Posted to microsoft.public.excel.programming
|
|||
|
|||
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
Posted to microsoft.public.excel.programming
|
|||
|
|||
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 |
Display Modes | |
|
|
Similar Threads | ||||
Thread | Forum | |||
Macro error opening text file | Excel Discussion (Misc queries) | |||
Problems opening file | Excel Discussion (Misc queries) | |||
Opening text file in Excel through macro | Excel Programming | |||
Opening text file in Excel through macro | Excel Programming | |||
Opening text file in Excel through macro | Excel Programming |