Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 17
Default Combining two ideas?

Thanks to the NG, I'm able to open file(s) into my CURRENT workbook
this way...

If Fnum 0 Then
For Fnum = LBound(MyFiles) To UBound(MyFiles)
Set mybook = Workbooks.Open(MyPath & MyFiles(Fnum))
mybook.Worksheets(1).Copy after:= _

basebook.Sheets(basebook.Sheets.Count)

On Error Resume Next
ActiveSheet.Name = mybook.Name
On Error GoTo 0

' You can use this if you want to copy only the values
' With ActiveSheet.UsedRange
' .Value = .Value
' End With

mybook.Close savechanges:=False
Next Fnum
End If

Now, recording a macro, I'm able to open a "|" delimited (NOT comma)
text file this way

For Fnum = LBound(MyFiles) To UBound(MyFiles)
Workbooks.OpenText Filename:= _
fName(Fnum), Origin:=437, StartRow _
:=1, DataType:=xlDelimited, TextQualifier:=xlDoubleQuote, _
ConsecutiveDelimiter:=False, Tab:=False, Semicolon:=False,
Comma:=False _
, Space:=False, Other:=True, OtherChar:="|",
FieldInfo:=Array(1, 1), _
TrailingMinusNumbers:=True
Next Fnum

However, how can I effectively do this?

For Fnum = LBound(MyFiles) To UBound(MyFiles)
' SYNTAX IS FOR ILLUSTRATION ONLY - OBVIOUSLY IT"S WRONG
Set mybook = Workbooks.OpenText Filename:= _
fName(Fnum), Origin:=437,
StartRow _
:=1, DataType:=xlDelimited,
TextQualifier:=xlDoubleQuote, _
ConsecutiveDelimiter:=False,
Tab:=False, Semicolon:=False, Comma:=False _
, Space:=False, Other:=True,
OtherChar:="|", FieldInfo:=Array(1, 1), _
TrailingMinusNumbers:=True
mybook.Worksheets(1).Copy after:= _

basebook.Sheets(basebook.Sheets.Count)

On Error Resume Next
ActiveSheet.Name = mybook.Name
On Error GoTo 0

' You can use this if you want to copy only the values
' With ActiveSheet.UsedRange
' .Value = .Value
' End With

mybook.Close savechanges:=False
Next Fnum
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35,218
Default Combining two ideas?

As soon as you open the text file, you can assign it to myBook. It'll be the
activeworkbook:

If Fnum 0 Then
For Fnum = LBound(MyFiles) To UBound(MyFiles)

Workbooks.OpenText Filename:=fName(Fnum), _
Origin:=437, StartRow:=1, DataType:=xlDelimited, _
TextQualifier:=xlDoubleQuote, _
ConsecutiveDelimiter:=False, Tab:=False, _
Semicolon:=False, Comma:=False, Space:=False, _
Other:=True, OtherChar:="|", FieldInfo:=Array(1, 1), _
TrailingMinusNumbers:=True

Set mybook = ActiveWorkbook 'the .txt file you just opened

mybook.Worksheets(1).Copy _
after:=basebook.Sheets(basebook.Sheets.Count)

On Error Resume Next
ActiveSheet.Name = mybook.Name
On Error GoTo 0

' You can use this if you want to copy only the values
' With ActiveSheet.UsedRange
' .Value = .Value
' End With

mybook.Close savechanges:=False
Next Fnum
End If

Zilla wrote:

Thanks to the NG, I'm able to open file(s) into my CURRENT workbook
this way...

If Fnum 0 Then
For Fnum = LBound(MyFiles) To UBound(MyFiles)
Set mybook = Workbooks.Open(MyPath & MyFiles(Fnum))
mybook.Worksheets(1).Copy after:= _

basebook.Sheets(basebook.Sheets.Count)

On Error Resume Next
ActiveSheet.Name = mybook.Name
On Error GoTo 0

' You can use this if you want to copy only the values
' With ActiveSheet.UsedRange
' .Value = .Value
' End With

mybook.Close savechanges:=False
Next Fnum
End If

Now, recording a macro, I'm able to open a "|" delimited (NOT comma)
text file this way

For Fnum = LBound(MyFiles) To UBound(MyFiles)
Workbooks.OpenText Filename:= _
fName(Fnum), Origin:=437, StartRow _
:=1, DataType:=xlDelimited, TextQualifier:=xlDoubleQuote, _
ConsecutiveDelimiter:=False, Tab:=False, Semicolon:=False,
Comma:=False _
, Space:=False, Other:=True, OtherChar:="|",
FieldInfo:=Array(1, 1), _
TrailingMinusNumbers:=True
Next Fnum

However, how can I effectively do this?

For Fnum = LBound(MyFiles) To UBound(MyFiles)
' SYNTAX IS FOR ILLUSTRATION ONLY - OBVIOUSLY IT"S WRONG
Set mybook = Workbooks.OpenText Filename:= _
fName(Fnum), Origin:=437,
StartRow _
:=1, DataType:=xlDelimited,
TextQualifier:=xlDoubleQuote, _
ConsecutiveDelimiter:=False,
Tab:=False, Semicolon:=False, Comma:=False _
, Space:=False, Other:=True,
OtherChar:="|", FieldInfo:=Array(1, 1), _
TrailingMinusNumbers:=True
mybook.Worksheets(1).Copy after:= _

basebook.Sheets(basebook.Sheets.Count)

On Error Resume Next
ActiveSheet.Name = mybook.Name
On Error GoTo 0

' You can use this if you want to copy only the values
' With ActiveSheet.UsedRange
' .Value = .Value
' End With

mybook.Close savechanges:=False
Next Fnum


--

Dave Peterson
  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 17
Default Combining two ideas?

On Jan 15, 7:41 pm, Dave Peterson wrote:
As soon as you open the text file, you can assign it to myBook. It'll be the
activeworkbook:

If Fnum 0 Then
For Fnum = LBound(MyFiles) To UBound(MyFiles)

Workbooks.OpenText Filename:=fName(Fnum), _
Origin:=437, StartRow:=1, DataType:=xlDelimited, _
TextQualifier:=xlDoubleQuote, _
ConsecutiveDelimiter:=False, Tab:=False, _
Semicolon:=False, Comma:=False, Space:=False, _
Other:=True, OtherChar:="|", FieldInfo:=Array(1, 1), _
TrailingMinusNumbers:=True

Set mybook = ActiveWorkbook 'the .txt file you just opened

mybook.Worksheets(1).Copy _
after:=basebook.Sheets(basebook.Sheets.Count)

On Error Resume Next
ActiveSheet.Name = mybook.Name
On Error GoTo 0

' You can use this if you want to copy only the values
' With ActiveSheet.UsedRange
' .Value = .Value
' End With

mybook.Close savechanges:=False
Next Fnum
End If



Zilla wrote:

Thanks to the NG, I'm able to open file(s) into my CURRENT workbook
this way...


If Fnum 0 Then
For Fnum = LBound(MyFiles) To UBound(MyFiles)
Set mybook = Workbooks.Open(MyPath & MyFiles(Fnum))
mybook.Worksheets(1).Copy after:= _


basebook.Sheets(basebook.Sheets.Count)


On Error Resume Next
ActiveSheet.Name = mybook.Name
On Error GoTo 0


' You can use this if you want to copy only the values
' With ActiveSheet.UsedRange
' .Value = .Value
' End With


mybook.Close savechanges:=False
Next Fnum
End If


Now, recording a macro, I'm able to open a "|" delimited (NOT comma)
text file this way


For Fnum = LBound(MyFiles) To UBound(MyFiles)
Workbooks.OpenText Filename:= _
fName(Fnum), Origin:=437, StartRow _
:=1, DataType:=xlDelimited, TextQualifier:=xlDoubleQuote, _
ConsecutiveDelimiter:=False, Tab:=False, Semicolon:=False,
Comma:=False _
, Space:=False, Other:=True, OtherChar:="|",
FieldInfo:=Array(1, 1), _
TrailingMinusNumbers:=True
Next Fnum


However, how can I effectively do this?


For Fnum = LBound(MyFiles) To UBound(MyFiles)
' SYNTAX IS FOR ILLUSTRATION ONLY - OBVIOUSLY IT"S WRONG
Set mybook = Workbooks.OpenText Filename:= _
fName(Fnum), Origin:=437,
StartRow _
:=1, DataType:=xlDelimited,
TextQualifier:=xlDoubleQuote, _
ConsecutiveDelimiter:=False,
Tab:=False, Semicolon:=False, Comma:=False _
, Space:=False, Other:=True,
OtherChar:="|", FieldInfo:=Array(1, 1), _
TrailingMinusNumbers:=True
mybook.Worksheets(1).Copy after:= _


basebook.Sheets(basebook.Sheets.Count)


On Error Resume Next
ActiveSheet.Name = mybook.Name
On Error GoTo 0


' You can use this if you want to copy only the values
' With ActiveSheet.UsedRange
' .Value = .Value
' End With


mybook.Close savechanges:=False
Next Fnum


--

Dave Peterson


You rock man! Thanks!!
  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,123
Default Combining two ideas?

hi Zilla

Have you test this one
http://www.rondebruin.nl/txtcsv.htm

--

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


"Zilla" wrote in message ...
Thanks to the NG, I'm able to open file(s) into my CURRENT workbook
this way...

If Fnum 0 Then
For Fnum = LBound(MyFiles) To UBound(MyFiles)
Set mybook = Workbooks.Open(MyPath & MyFiles(Fnum))
mybook.Worksheets(1).Copy after:= _

basebook.Sheets(basebook.Sheets.Count)

On Error Resume Next
ActiveSheet.Name = mybook.Name
On Error GoTo 0

' You can use this if you want to copy only the values
' With ActiveSheet.UsedRange
' .Value = .Value
' End With

mybook.Close savechanges:=False
Next Fnum
End If

Now, recording a macro, I'm able to open a "|" delimited (NOT comma)
text file this way

For Fnum = LBound(MyFiles) To UBound(MyFiles)
Workbooks.OpenText Filename:= _
fName(Fnum), Origin:=437, StartRow _
:=1, DataType:=xlDelimited, TextQualifier:=xlDoubleQuote, _
ConsecutiveDelimiter:=False, Tab:=False, Semicolon:=False,
Comma:=False _
, Space:=False, Other:=True, OtherChar:="|",
FieldInfo:=Array(1, 1), _
TrailingMinusNumbers:=True
Next Fnum

However, how can I effectively do this?

For Fnum = LBound(MyFiles) To UBound(MyFiles)
' SYNTAX IS FOR ILLUSTRATION ONLY - OBVIOUSLY IT"S WRONG
Set mybook = Workbooks.OpenText Filename:= _
fName(Fnum), Origin:=437,
StartRow _
:=1, DataType:=xlDelimited,
TextQualifier:=xlDoubleQuote, _
ConsecutiveDelimiter:=False,
Tab:=False, Semicolon:=False, Comma:=False _
, Space:=False, Other:=True,
OtherChar:="|", FieldInfo:=Array(1, 1), _
TrailingMinusNumbers:=True
mybook.Worksheets(1).Copy after:= _

basebook.Sheets(basebook.Sheets.Count)

On Error Resume Next
ActiveSheet.Name = mybook.Name
On Error GoTo 0

' You can use this if you want to copy only the values
' With ActiveSheet.UsedRange
' .Value = .Value
' End With

mybook.Close savechanges:=False
Next Fnum

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
any ideas if this can be done CarlM[_2_] Excel Worksheet Functions 2 October 27th 09 03:52 PM
Any ideas on how to do this? michael.beckinsale Excel Programming 7 July 22nd 06 10:33 AM
Any Ideas? Jimbo1[_10_] Excel Programming 1 April 20th 06 04:24 PM
Any Ideas Greg B Excel Discussion (Misc queries) 7 May 16th 05 03:41 AM
Ant ideas? Tompy[_2_] Excel Programming 0 September 26th 04 12:06 PM


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