Open .txt file into .xls file using excel 2013

JSemper

New Member
Joined
Jul 17, 2014
Messages
21
Below is a code which when run on a PC with excel 2013 brings up and error regarding too many columns/rows for destination sheet. I know this is due to the text file being opened in excel (excel 2013 extension) and then trying to move to the destination sheet which is a .xls file which has a smaller number of rows & columns.

The sheet for now, needs to work on both excel 2007 & 2013 suites.

Is there a way of forcing the text file to be opened into a .xls file format.

I could work around it by saving the newly created file as a .xls format and then re-open it before moving into the destination sheet, but it's bugging me that I cant find a way of doing it without this workaround.

Code:

Sheets("Sheet1").Select
ActiveWindow.SelectedSheets.Delete
Workbooks.OpenText Filename:="P:\pilot\TOIC194.TXT", Origin:=xlWindows, StartRow:=2, DataType:=xlDelimited, TextQualifier:=xlNone, _
ConsecutiveDelimiter:=False, Tab:=False, Semicolon:=False, Comma:=True, Space:=False, Other:=False, FieldInfo:=Array( _
Array(1, 2), Array(2, 2), Array(3, 2), Array(4, 2), Array(5, 2), Array(6, 2), Array(7, 1), Array(8, 1), Array(9, 1), Array(10, 1), Array(11, 1), Array(12, 1) _
, Array(13, 1), Array(14, 1), Array(15, 1), Array(16, 1), Array(17, 1), Array(18, 1), Array(19, 1), Array(20, 1), Array(21, 1), Array(22, 1), Array(23, 1), _
Array(24, 1), Array(25, 1), Array(26, 1), Array(27, 1), Array(28, 1), Array(29, 1), Array(30, 1), Array(31, 1), Array(32, 1), Array(33, 1), Array(34, 1), _
Array(35, 1), Array(36, 1), Array(37, 1), Array(38, 1), Array(39, 1), Array(40, 1), Array(41, 1), Array(42, 1), Array(43, 1), Array(44, 1), Array(45, 1), _
Array(46, 1), Array(47, 1), Array(48, 1), Array(49, 1))
Sheets("TOIC194").Select
Sheets("TOIC194").Name = "Sheet1"
Sheets("Sheet1").Move Workbooks("fvd.XLS").Sheets(1)
 

Excel Facts

How to show all formulas in Excel?
Press Ctrl+` to show all formulas. Press it again to toggle back to numbers. The grave accent is often under the tilde on US keyboards.
Hi
Maybe I have misunderstood, but could you not import the text file and then save it as .xls
 
Upvote 0
Hi
Maybe I have misunderstood, but could you not import the text file and then save it as .xls

Thats what I have ended up doing, I just thought maybe when importing the text file, I could import it into a .xls file. As there are other macros which I do this with.

importing then saving as a .xls file works just fine.
 
Upvote 0

Forum statistics

Threads
1,214,899
Messages
6,122,155
Members
449,068
Latest member
shiz11713

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top