#1   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 96
Default Open File

Is there a way to tell this macro to open in cell A6 and to preserve the
formatting of the worksheet?

Sub Macro1()
'
' Macro1 Macro
' Macro recorded 3/13/2009
'

'
Workbooks.OpenText Filename:= _
"\\admis.adm\kcdfs\kcusers\A829917\My Documents\Seg Positions.txt",
Origin:= _
xlWindows, StartRow:=6, DataType:=xlFixedWidth,
FieldInfo:=Array(Array(0, 1), _
Array(10, 1), Array(16, 1), Array(41, 1)), TrailingMinusNumbers:=True
End Sub

  #2   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 35,218
Default Open File

This is opening a text file. There is no formatting associated with text
files--they're plain text. But you can specify how each field should be treated
(general, text, date, skipped) in that fieldinfo parm.

If you wanted, you could insert 5 empty lines at the top of the text file or
have your macro insert 5 rows at the top of the worksheet.

You could add a line to your code after the file is opened:

activesheet.rows(1).resize(5).insert

And you could apply any formatting you want (number/font/fill) after the data is
imported. Do it manually and record a macro. Then add this recorded code to
your existing macro and you should be close to set.


chrisnsmith wrote:

Is there a way to tell this macro to open in cell A6 and to preserve the
formatting of the worksheet?

Sub Macro1()
'
' Macro1 Macro
' Macro recorded 3/13/2009
'

'
Workbooks.OpenText Filename:= _
"\\admis.adm\kcdfs\kcusers\A829917\My Documents\Seg Positions.txt",
Origin:= _
xlWindows, StartRow:=6, DataType:=xlFixedWidth,
FieldInfo:=Array(Array(0, 1), _
Array(10, 1), Array(16, 1), Array(41, 1)), TrailingMinusNumbers:=True
End Sub


--

Dave Peterson
  #3   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 10
Default Open File

Hi,
You should be able to accomplish this without a macro by using the text
import feature.
With this feature you can specify a starting cell to place the data and also
preserve cell formatting.
The properties that you set can be saved with the file and used as a sort of
template for opening (importing) the text file.
You may want to start here;
http://www.j-walk.com/ss/excel/usertips/tip030.htm
If you're using Excel 2007 try he
http://office.microsoft.com/en-us/ex...997251033.aspx
Best wishes.

Dave



"chrisnsmith" wrote in message
...
Is there a way to tell this macro to open in cell A6 and to preserve the
formatting of the worksheet?

Sub Macro1()
'
' Macro1 Macro
' Macro recorded 3/13/2009
'

'
Workbooks.OpenText Filename:= _
"\\admis.adm\kcdfs\kcusers\A829917\My Documents\Seg Positions.txt",
Origin:= _
xlWindows, StartRow:=6, DataType:=xlFixedWidth,
FieldInfo:=Array(Array(0, 1), _
Array(10, 1), Array(16, 1), Array(41, 1)),
TrailingMinusNumbers:=True
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
excel 2003 saved file will not open without a blank workbook open Bob Excel Discussion (Misc queries) 4 November 11th 06 04:24 PM
In Excel - Use Windows Explorer instead of File Open to open file KymY Excel Discussion (Misc queries) 1 August 5th 06 09:59 PM
Open email windows can't open, excel shreadsheet file .xls ? skiz Excel Discussion (Misc queries) 0 October 2nd 05 07:03 PM
file open via IE hyperlink causes already open files to shrink and tile Marc Setting up and Configuration of Excel 0 May 4th 05 08:13 PM
How do I stop Excel from closing the open file each time I open a. Welsin Setting up and Configuration of Excel 3 January 8th 05 11:16 PM


All times are GMT +1. The time now is 07:09 PM.

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

About Us

"It's about Microsoft Excel"