PC Review


Reply
Thread Tools Rate Thread

Combining two ideas?

 
 
Zilla
Guest
Posts: n/a
 
      16th Jan 2008
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 With Quote
 
 
 
 
Dave Peterson
Guest
Posts: n/a
 
      16th Jan 2008
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
 
Reply With Quote
 
Zilla
Guest
Posts: n/a
 
      16th Jan 2008
On Jan 15, 7:41 pm, Dave Peterson <peter...@verizonXSPAM.net> 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!!
 
Reply With Quote
 
Ron de Bruin
Guest
Posts: n/a
 
      16th Jan 2008
hi Zilla

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

--

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


"Zilla" <(E-Mail Removed)> wrote in message news:cfa92ceb-c569-4d91-bbf9-(E-Mail Removed)...
> 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 With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
any ideas capser717 Microsoft Excel Crashes 1 31st Jan 2008 05:23 PM
Any Ideas? Aaron-McLeod Microsoft Outlook 2 17th Oct 2006 10:12 PM
Any ideas David Microsoft Access Reports 10 15th Feb 2005 12:40 AM
Ideas Simonglencross Microsoft Access Forms 5 26th Nov 2004 08:49 PM
Re: Ideas? Frederick Shorts Printers 0 10th Mar 2004 02:52 AM


Features
 

Advertising
 

Newsgroups
 


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