Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 67
Default Worksheet.opentext....???

Is there any way I can open a text file in the workbook that the
macros is running in. Everytime I try with my code it automatically
opens a new workbook. I have looked at other comments for other people
but none of them work because I have a datatype and fieldinfo.

This is my code to open a txt file

Dim UF As Variant
Dim SL As Variant
UF = Application.GetOpenFilename(FileFilter:="TXT Files(*.txt),*.txt",
Title:="log")

Workbooks.OpenText Filename:=UF, DataType:=xlFixedWidth,
FieldInfo:=Array(Array(0, 2))

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 6,953
Default Worksheet.opentext....???

Opentext places the textfile in a new workbook. It is trivial to then copy
it to your existing workbook - that is the method I use.

Alternately you can use querytable to do it directly. This is an old post
that illustrates:
-------------<old post-----------------

Sub TestGetTxtFile()


'


' TestGetTxtFile Macro


' Macro recorded 10/7/2003 by Authorized User


'


With ActiveSheet.QueryTables.Add(Connection:= _


"TEXT;C:\NWACCESS\DATA\TIR Updates\test.txt",
Destination:=Range("A1"))
.Name = "test"
.FieldNames = True
.RowNumbers = False
.FillAdjacentFormulas = False
.PreserveFormatting = True
.RefreshOnFileOpen = False
.RefreshStyle = xlInsertDeleteCells
.SavePassword = False
.SaveData = True
.AdjustColumnWidth = True
.RefreshPeriod = 0
.TextFilePromptOnRefresh = False
.TextFilePlatform = xlWindows
.TextFileStartRow = 1
.TextFileParseType = xlDelimited
.TextFileTextQualifier = xlTextQualifierDoubleQuote
.TextFileConsecutiveDelimiter = False
.TextFileTabDelimiter = False
.TextFileSemicolonDelimiter = False
.TextFileCommaDelimiter = True
.TextFileSpaceDelimiter = False
.TextFileColumnDataTypes = Array(1, 1, 2, 1, 1, 2, 1)
.Refresh BackgroundQuery:=False
End With
End Sub


So:


You're using the QueryTables collection object. Go to VBA help and type
that into the Answer Wizard box and read all about it.


If your text file is always saved as a certain name - "MyData mmddyy.txt"
(where mmddyy is a date identifier) into the same folder, then you can code
your file path and name to get the file without using a dialogue box.


Using the .TextFileColumnDataTypes = Array(1, 1, 2, 1, 1, 2, 1) line, you
can specify if any columns are general, text, or numeric. I just used
General (1) and Text (2).


Before the End Sub, insert code to SaveAs with a file path and name, and you
should be good to go.

-----------<End Old Post-----------

--
Regards,
Tom Ogilvy

" wrote:

Is there any way I can open a text file in the workbook that the
macros is running in. Everytime I try with my code it automatically
opens a new workbook. I have looked at other comments for other people
but none of them work because I have a datatype and fieldinfo.

This is my code to open a txt file

Dim UF As Variant
Dim SL As Variant
UF = Application.GetOpenFilename(FileFilter:="TXT Files(*.txt),*.txt",
Title:="log")

Workbooks.OpenText Filename:=UF, DataType:=xlFixedWidth,
FieldInfo:=Array(Array(0, 2))


  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,123
Default Worksheet.opentext....???

Or use
http://www.cpearson.com/excel/imptext.htm


--

Regards Ron de Bruin
http://www.rondebruin.nl/tips.htm


"Tom Ogilvy" wrote in message ...
Opentext places the textfile in a new workbook. It is trivial to then copy
it to your existing workbook - that is the method I use.

Alternately you can use querytable to do it directly. This is an old post
that illustrates:
-------------<old post-----------------

Sub TestGetTxtFile()


'


' TestGetTxtFile Macro


' Macro recorded 10/7/2003 by Authorized User


'


With ActiveSheet.QueryTables.Add(Connection:= _


"TEXT;C:\NWACCESS\DATA\TIR Updates\test.txt",
Destination:=Range("A1"))
.Name = "test"
.FieldNames = True
.RowNumbers = False
.FillAdjacentFormulas = False
.PreserveFormatting = True
.RefreshOnFileOpen = False
.RefreshStyle = xlInsertDeleteCells
.SavePassword = False
.SaveData = True
.AdjustColumnWidth = True
.RefreshPeriod = 0
.TextFilePromptOnRefresh = False
.TextFilePlatform = xlWindows
.TextFileStartRow = 1
.TextFileParseType = xlDelimited
.TextFileTextQualifier = xlTextQualifierDoubleQuote
.TextFileConsecutiveDelimiter = False
.TextFileTabDelimiter = False
.TextFileSemicolonDelimiter = False
.TextFileCommaDelimiter = True
.TextFileSpaceDelimiter = False
.TextFileColumnDataTypes = Array(1, 1, 2, 1, 1, 2, 1)
.Refresh BackgroundQuery:=False
End With
End Sub


So:


You're using the QueryTables collection object. Go to VBA help and type
that into the Answer Wizard box and read all about it.


If your text file is always saved as a certain name - "MyData mmddyy.txt"
(where mmddyy is a date identifier) into the same folder, then you can code
your file path and name to get the file without using a dialogue box.


Using the .TextFileColumnDataTypes = Array(1, 1, 2, 1, 1, 2, 1) line, you
can specify if any columns are general, text, or numeric. I just used
General (1) and Text (2).


Before the End Sub, insert code to SaveAs with a file path and name, and you
should be good to go.

-----------<End Old Post-----------

--
Regards,
Tom Ogilvy

" wrote:

Is there any way I can open a text file in the workbook that the
macros is running in. Everytime I try with my code it automatically
opens a new workbook. I have looked at other comments for other people
but none of them work because I have a datatype and fieldinfo.

This is my code to open a txt file

Dim UF As Variant
Dim SL As Variant
UF = Application.GetOpenFilename(FileFilter:="TXT Files(*.txt),*.txt",
Title:="log")

Workbooks.OpenText Filename:=UF, DataType:=xlFixedWidth,
FieldInfo:=Array(Array(0, 2))


  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 6,953
Default Worksheet.opentext....???

Ron,
That is a good reference for a delimited file, but in his sample code he
showed

xlFixedWidth

So not sure it is applicable here.

--
Regards,
Tom Ogilvy


"Ron de Bruin" wrote:

Or use
http://www.cpearson.com/excel/imptext.htm


--

Regards Ron de Bruin
http://www.rondebruin.nl/tips.htm


"Tom Ogilvy" wrote in message ...
Opentext places the textfile in a new workbook. It is trivial to then copy
it to your existing workbook - that is the method I use.

Alternately you can use querytable to do it directly. This is an old post
that illustrates:
-------------<old post-----------------

Sub TestGetTxtFile()


'


' TestGetTxtFile Macro


' Macro recorded 10/7/2003 by Authorized User


'


With ActiveSheet.QueryTables.Add(Connection:= _


"TEXT;C:\NWACCESS\DATA\TIR Updates\test.txt",
Destination:=Range("A1"))
.Name = "test"
.FieldNames = True
.RowNumbers = False
.FillAdjacentFormulas = False
.PreserveFormatting = True
.RefreshOnFileOpen = False
.RefreshStyle = xlInsertDeleteCells
.SavePassword = False
.SaveData = True
.AdjustColumnWidth = True
.RefreshPeriod = 0
.TextFilePromptOnRefresh = False
.TextFilePlatform = xlWindows
.TextFileStartRow = 1
.TextFileParseType = xlDelimited
.TextFileTextQualifier = xlTextQualifierDoubleQuote
.TextFileConsecutiveDelimiter = False
.TextFileTabDelimiter = False
.TextFileSemicolonDelimiter = False
.TextFileCommaDelimiter = True
.TextFileSpaceDelimiter = False
.TextFileColumnDataTypes = Array(1, 1, 2, 1, 1, 2, 1)
.Refresh BackgroundQuery:=False
End With
End Sub


So:


You're using the QueryTables collection object. Go to VBA help and type
that into the Answer Wizard box and read all about it.


If your text file is always saved as a certain name - "MyData mmddyy.txt"
(where mmddyy is a date identifier) into the same folder, then you can code
your file path and name to get the file without using a dialogue box.


Using the .TextFileColumnDataTypes = Array(1, 1, 2, 1, 1, 2, 1) line, you
can specify if any columns are general, text, or numeric. I just used
General (1) and Text (2).


Before the End Sub, insert code to SaveAs with a file path and name, and you
should be good to go.

-----------<End Old Post-----------

--
Regards,
Tom Ogilvy

" wrote:

Is there any way I can open a text file in the workbook that the
macros is running in. Everytime I try with my code it automatically
opens a new workbook. I have looked at other comments for other people
but none of them work because I have a datatype and fieldinfo.

This is my code to open a txt file

Dim UF As Variant
Dim SL As Variant
UF = Application.GetOpenFilename(FileFilter:="TXT Files(*.txt),*.txt",
Title:="log")

Workbooks.OpenText Filename:=UF, DataType:=xlFixedWidth,
FieldInfo:=Array(Array(0, 2))





  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,123
Default Worksheet.opentext....???

Correct Tom

I am building a page on this moment to import a lot of txt files and use Chip's ImportTextFile
in the loop in one of the examples.
Testing opentext also but I think I go for the QueryTables because it is much faster
if you want to import a lot of txt files

Any thoughts ?


--

Regards Ron de Bruin
http://www.rondebruin.nl/tips.htm


"Tom Ogilvy" wrote in message ...
Ron,
That is a good reference for a delimited file, but in his sample code he
showed

xlFixedWidth

So not sure it is applicable here.

--
Regards,
Tom Ogilvy


"Ron de Bruin" wrote:

Or use
http://www.cpearson.com/excel/imptext.htm


--

Regards Ron de Bruin
http://www.rondebruin.nl/tips.htm


"Tom Ogilvy" wrote in message ...
Opentext places the textfile in a new workbook. It is trivial to then copy
it to your existing workbook - that is the method I use.

Alternately you can use querytable to do it directly. This is an old post
that illustrates:
-------------<old post-----------------

Sub TestGetTxtFile()


'


' TestGetTxtFile Macro


' Macro recorded 10/7/2003 by Authorized User


'


With ActiveSheet.QueryTables.Add(Connection:= _


"TEXT;C:\NWACCESS\DATA\TIR Updates\test.txt",
Destination:=Range("A1"))
.Name = "test"
.FieldNames = True
.RowNumbers = False
.FillAdjacentFormulas = False
.PreserveFormatting = True
.RefreshOnFileOpen = False
.RefreshStyle = xlInsertDeleteCells
.SavePassword = False
.SaveData = True
.AdjustColumnWidth = True
.RefreshPeriod = 0
.TextFilePromptOnRefresh = False
.TextFilePlatform = xlWindows
.TextFileStartRow = 1
.TextFileParseType = xlDelimited
.TextFileTextQualifier = xlTextQualifierDoubleQuote
.TextFileConsecutiveDelimiter = False
.TextFileTabDelimiter = False
.TextFileSemicolonDelimiter = False
.TextFileCommaDelimiter = True
.TextFileSpaceDelimiter = False
.TextFileColumnDataTypes = Array(1, 1, 2, 1, 1, 2, 1)
.Refresh BackgroundQuery:=False
End With
End Sub


So:


You're using the QueryTables collection object. Go to VBA help and type
that into the Answer Wizard box and read all about it.


If your text file is always saved as a certain name - "MyData mmddyy.txt"
(where mmddyy is a date identifier) into the same folder, then you can code
your file path and name to get the file without using a dialogue box.


Using the .TextFileColumnDataTypes = Array(1, 1, 2, 1, 1, 2, 1) line, you
can specify if any columns are general, text, or numeric. I just used
General (1) and Text (2).


Before the End Sub, insert code to SaveAs with a file path and name, and you
should be good to go.

-----------<End Old Post-----------

--
Regards,
Tom Ogilvy

" wrote:

Is there any way I can open a text file in the workbook that the
macros is running in. Everytime I try with my code it automatically
opens a new workbook. I have looked at other comments for other people
but none of them work because I have a datatype and fieldinfo.

This is my code to open a txt file

Dim UF As Variant
Dim SL As Variant
UF = Application.GetOpenFilename(FileFilter:="TXT Files(*.txt),*.txt",
Title:="log")

Workbooks.OpenText Filename:=UF, DataType:=xlFixedWidth,
FieldInfo:=Array(Array(0, 2))



  #7   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,123
Default Worksheet.opentext....???

Here it is
http://www.rondebruin.nl/txtcsv.htm



--

Regards Ron de Bruin
http://www.rondebruin.nl/tips.htm


"Ron de Bruin" wrote in message ...
Correct Tom

I am building a page on this moment to import a lot of txt files and use Chip's ImportTextFile
in the loop in one of the examples.
Testing opentext also but I think I go for the QueryTables because it is much faster
if you want to import a lot of txt files

Any thoughts ?


--

Regards Ron de Bruin
http://www.rondebruin.nl/tips.htm


"Tom Ogilvy" wrote in message ...
Ron,
That is a good reference for a delimited file, but in his sample code he
showed

xlFixedWidth

So not sure it is applicable here.

--
Regards,
Tom Ogilvy


"Ron de Bruin" wrote:

Or use
http://www.cpearson.com/excel/imptext.htm


--

Regards Ron de Bruin
http://www.rondebruin.nl/tips.htm


"Tom Ogilvy" wrote in message ...
Opentext places the textfile in a new workbook. It is trivial to then copy
it to your existing workbook - that is the method I use.

Alternately you can use querytable to do it directly. This is an old post
that illustrates:
-------------<old post-----------------

Sub TestGetTxtFile()


'


' TestGetTxtFile Macro


' Macro recorded 10/7/2003 by Authorized User


'


With ActiveSheet.QueryTables.Add(Connection:= _


"TEXT;C:\NWACCESS\DATA\TIR Updates\test.txt",
Destination:=Range("A1"))
.Name = "test"
.FieldNames = True
.RowNumbers = False
.FillAdjacentFormulas = False
.PreserveFormatting = True
.RefreshOnFileOpen = False
.RefreshStyle = xlInsertDeleteCells
.SavePassword = False
.SaveData = True
.AdjustColumnWidth = True
.RefreshPeriod = 0
.TextFilePromptOnRefresh = False
.TextFilePlatform = xlWindows
.TextFileStartRow = 1
.TextFileParseType = xlDelimited
.TextFileTextQualifier = xlTextQualifierDoubleQuote
.TextFileConsecutiveDelimiter = False
.TextFileTabDelimiter = False
.TextFileSemicolonDelimiter = False
.TextFileCommaDelimiter = True
.TextFileSpaceDelimiter = False
.TextFileColumnDataTypes = Array(1, 1, 2, 1, 1, 2, 1)
.Refresh BackgroundQuery:=False
End With
End Sub


So:


You're using the QueryTables collection object. Go to VBA help and type
that into the Answer Wizard box and read all about it.


If your text file is always saved as a certain name - "MyData mmddyy.txt"
(where mmddyy is a date identifier) into the same folder, then you can code
your file path and name to get the file without using a dialogue box.


Using the .TextFileColumnDataTypes = Array(1, 1, 2, 1, 1, 2, 1) line, you
can specify if any columns are general, text, or numeric. I just used
General (1) and Text (2).


Before the End Sub, insert code to SaveAs with a file path and name, and you
should be good to go.

-----------<End Old Post-----------

--
Regards,
Tom Ogilvy

" wrote:

Is there any way I can open a text file in the workbook that the
macros is running in. Everytime I try with my code it automatically
opens a new workbook. I have looked at other comments for other people
but none of them work because I have a datatype and fieldinfo.

This is my code to open a txt file

Dim UF As Variant
Dim SL As Variant
UF = Application.GetOpenFilename(FileFilter:="TXT Files(*.txt),*.txt",
Title:="log")

Workbooks.OpenText Filename:=UF, DataType:=xlFixedWidth,
FieldInfo:=Array(Array(0, 2))



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
opentext neia Excel Programming 0 May 8th 06 04:31 PM
OpenText Mike Archer Excel Programming 1 February 13th 06 09:22 PM
opentext banavas[_13_] Excel Programming 3 June 28th 04 02:25 PM
After OpenText all pastes from external apps use format from OpenText Jim[_31_] Excel Programming 1 November 8th 03 02:17 AM
Using Workbooks.OpenText to read a tab-delimited file into a worksheet Dan E[_2_] Excel Programming 0 August 19th 03 08:02 PM


All times are GMT +1. The time now is 11:49 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"