#1   Report Post  
Posted to microsoft.public.excel.programming
al al is offline
external usenet poster
 
Posts: 363
Default Open CSV

Hello
I am trying to modify the following code to open all files in current folder
*a.csv The code now opens the same files saved as xls. How do I modify to
open CSV?
Im guessing its in
.FileType = msoFileTypeExcelWorkbooks
and
If InStr(1, .FoundFiles(i), "A.xls", vbTextCompare) Then

But Im not sure of syntax.....


Sub Summary()

Dim myCell As Range
Dim myBook As Workbook
Dim i As Long
Dim r As Range, r1 As Range

With Application
.DisplayAlerts = False
.EnableEvents = False
.ScreenUpdating = False
End With

With Application.FileSearch
.NewSearch
'Copy or move this workbook to the folder with
'the files that you want to summarize
.LookIn = ThisWorkbook.Path
.FileType = msoFileTypeExcelWorkbooks
If .Execute() 0 Then
For i = 1 To .FoundFiles.Count
If .FoundFiles(i) < ThisWorkbook.FullName Then
If InStr(1, .FoundFiles(i), "A.xls", vbTextCompare) Then
Set myBook = Workbooks.Open(.FoundFiles(i))
myBook.Worksheets("Table").Select
Set r = myBook.Worksheets("Table").Range("a3:f51")
Set r1 = ThisWorkbook.Worksheets(1). _
Range("a65536").End(xlUp)
If r1.Row = 1 Then Set r1 = r1.Offset(1, 0)
If Not IsEmpty(r1) Then Set r1 = r1.Offset(1, 0)
r.Copy Destination:=r1
myBook.Close SaveChanges:=False
End If ' Instr
End If ' not thisworkbook
Next i
End If
End With

With Application
.DisplayAlerts = True
.EnableEvents = True
.ScreenUpdating = True
End With

ThisWorkbook.SaveAs Application.GetSaveAsFilename

End Sub


Thanks!!
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35,218
Default Open CSV

I'd drop the .filetype line and use:


With Application.FileSearch
.NewSearch
.Filename = "*.csv"
'''

Some versions of windows will want:
.Filename = ".csv"
(I don't recall which!)

And then change:

If InStr(1, .FoundFiles(i), "A.xls", vbTextCompare) Then
to
If InStr(1, .FoundFiles(i), "A.csv", vbTextCompare) Then



Al wrote:

Hello
I am trying to modify the following code to open all files in current folder
*a.csv The code now opens the same files saved as xls. How do I modify to
open CSV?
Im guessing its in
.FileType = msoFileTypeExcelWorkbooks
and
If InStr(1, .FoundFiles(i), "A.xls", vbTextCompare) Then

But Im not sure of syntax.....

Sub Summary()

Dim myCell As Range
Dim myBook As Workbook
Dim i As Long
Dim r As Range, r1 As Range

With Application
.DisplayAlerts = False
.EnableEvents = False
.ScreenUpdating = False
End With

With Application.FileSearch
.NewSearch
'Copy or move this workbook to the folder with
'the files that you want to summarize
.LookIn = ThisWorkbook.Path
.FileType = msoFileTypeExcelWorkbooks
If .Execute() 0 Then
For i = 1 To .FoundFiles.Count
If .FoundFiles(i) < ThisWorkbook.FullName Then
If InStr(1, .FoundFiles(i), "A.xls", vbTextCompare) Then
Set myBook = Workbooks.Open(.FoundFiles(i))
myBook.Worksheets("Table").Select
Set r = myBook.Worksheets("Table").Range("a3:f51")
Set r1 = ThisWorkbook.Worksheets(1). _
Range("a65536").End(xlUp)
If r1.Row = 1 Then Set r1 = r1.Offset(1, 0)
If Not IsEmpty(r1) Then Set r1 = r1.Offset(1, 0)
r.Copy Destination:=r1
myBook.Close SaveChanges:=False
End If ' Instr
End If ' not thisworkbook
Next i
End If
End With

With Application
.DisplayAlerts = True
.EnableEvents = True
.ScreenUpdating = True
End With

ThisWorkbook.SaveAs Application.GetSaveAsFilename

End Sub

Thanks!!


--

Dave Peterson
  #3   Report Post  
Posted to microsoft.public.excel.programming
al al is offline
external usenet poster
 
Posts: 363
Default Open CSV

THanks for the reply!
Where will the matching end with go?
THanks again!

"Dave Peterson" wrote:

I'd drop the .filetype line and use:


With Application.FileSearch
.NewSearch
.Filename = "*.csv"
'''

Some versions of windows will want:
.Filename = ".csv"
(I don't recall which!)

And then change:

If InStr(1, .FoundFiles(i), "A.xls", vbTextCompare) Then
to
If InStr(1, .FoundFiles(i), "A.csv", vbTextCompare) Then



Al wrote:

Hello
I am trying to modify the following code to open all files in current folder
*a.csv The code now opens the same files saved as xls. How do I modify to
open CSV?
Im guessing its in
.FileType = msoFileTypeExcelWorkbooks
and
If InStr(1, .FoundFiles(i), "A.xls", vbTextCompare) Then

But Im not sure of syntax.....

Sub Summary()

Dim myCell As Range
Dim myBook As Workbook
Dim i As Long
Dim r As Range, r1 As Range

With Application
.DisplayAlerts = False
.EnableEvents = False
.ScreenUpdating = False
End With

With Application.FileSearch
.NewSearch
'Copy or move this workbook to the folder with
'the files that you want to summarize
.LookIn = ThisWorkbook.Path
.FileType = msoFileTypeExcelWorkbooks
If .Execute() 0 Then
For i = 1 To .FoundFiles.Count
If .FoundFiles(i) < ThisWorkbook.FullName Then
If InStr(1, .FoundFiles(i), "A.xls", vbTextCompare) Then
Set myBook = Workbooks.Open(.FoundFiles(i))
myBook.Worksheets("Table").Select
Set r = myBook.Worksheets("Table").Range("a3:f51")
Set r1 = ThisWorkbook.Worksheets(1). _
Range("a65536").End(xlUp)
If r1.Row = 1 Then Set r1 = r1.Offset(1, 0)
If Not IsEmpty(r1) Then Set r1 = r1.Offset(1, 0)
r.Copy Destination:=r1
myBook.Close SaveChanges:=False
End If ' Instr
End If ' not thisworkbook
Next i
End If
End With

With Application
.DisplayAlerts = True
.EnableEvents = True
.ScreenUpdating = True
End With

ThisWorkbook.SaveAs Application.GetSaveAsFilename

End Sub

Thanks!!


--

Dave Peterson

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35,218
Default Open CSV

This compiled ok--but I didn't test it:

Option Explicit
Sub Summary()

Dim myCell As Range
Dim myBook As Workbook
Dim i As Long
Dim r As Range, r1 As Range

With Application
.DisplayAlerts = False
.EnableEvents = False
.ScreenUpdating = False
End With

With Application.FileSearch
.NewSearch
'Copy or move this workbook to the folder with
'the files that you want to summarize
.LookIn = ThisWorkbook.Path
.Filename = ".csv"
'.FileType = msoFileTypeExcelWorkbooks
If .Execute() 0 Then
For i = 1 To .FoundFiles.Count
If .FoundFiles(i) < ThisWorkbook.FullName Then
If InStr(1, .FoundFiles(i), "A.csv", vbTextCompare) Then
Set myBook = Workbooks.Open(.FoundFiles(i))
myBook.Worksheets("Table").Select
Set r = myBook.Worksheets("Table").Range("a3:f51")
Set r1 = ThisWorkbook.Worksheets(1). _
Range("a65536").End(xlUp)
If r1.Row = 1 Then Set r1 = r1.Offset(1, 0)
If Not IsEmpty(r1) Then Set r1 = r1.Offset(1, 0)
r.Copy Destination:=r1
myBook.Close SaveChanges:=False
End If ' Instr
End If ' not thisworkbook
Next i
End If
End With

With Application
.DisplayAlerts = True
.EnableEvents = True
.ScreenUpdating = True
End With

ThisWorkbook.SaveAs Application.GetSaveAsFilename

End Sub

Al wrote:

THanks for the reply!
Where will the matching end with go?
THanks again!

"Dave Peterson" wrote:

I'd drop the .filetype line and use:


With Application.FileSearch
.NewSearch
.Filename = "*.csv"
'''

Some versions of windows will want:
.Filename = ".csv"
(I don't recall which!)

And then change:

If InStr(1, .FoundFiles(i), "A.xls", vbTextCompare) Then
to
If InStr(1, .FoundFiles(i), "A.csv", vbTextCompare) Then



Al wrote:

Hello
I am trying to modify the following code to open all files in current folder
*a.csv The code now opens the same files saved as xls. How do I modify to
open CSV?
Im guessing its in
.FileType = msoFileTypeExcelWorkbooks
and
If InStr(1, .FoundFiles(i), "A.xls", vbTextCompare) Then

But Im not sure of syntax.....

Sub Summary()

Dim myCell As Range
Dim myBook As Workbook
Dim i As Long
Dim r As Range, r1 As Range

With Application
.DisplayAlerts = False
.EnableEvents = False
.ScreenUpdating = False
End With

With Application.FileSearch
.NewSearch
'Copy or move this workbook to the folder with
'the files that you want to summarize
.LookIn = ThisWorkbook.Path
.FileType = msoFileTypeExcelWorkbooks
If .Execute() 0 Then
For i = 1 To .FoundFiles.Count
If .FoundFiles(i) < ThisWorkbook.FullName Then
If InStr(1, .FoundFiles(i), "A.xls", vbTextCompare) Then
Set myBook = Workbooks.Open(.FoundFiles(i))
myBook.Worksheets("Table").Select
Set r = myBook.Worksheets("Table").Range("a3:f51")
Set r1 = ThisWorkbook.Worksheets(1). _
Range("a65536").End(xlUp)
If r1.Row = 1 Then Set r1 = r1.Offset(1, 0)
If Not IsEmpty(r1) Then Set r1 = r1.Offset(1, 0)
r.Copy Destination:=r1
myBook.Close SaveChanges:=False
End If ' Instr
End If ' not thisworkbook
Next i
End If
End With

With Application
.DisplayAlerts = True
.EnableEvents = True
.ScreenUpdating = True
End With

ThisWorkbook.SaveAs Application.GetSaveAsFilename

End Sub

Thanks!!


--

Dave Peterson


--

Dave Peterson
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
ON OPEN VBA Code input incorrectly now excel sheet wont open mmartin New Users to Excel 1 February 16th 11 11:33 PM
Opening Excel, Book1 opens, remains open with other workbook open DanieB Excel Discussion (Misc queries) 0 September 3rd 09 08:23 AM
excel 2003 saved file will not open without a blank workbook open Bob Excel Discussion (Misc queries) 4 November 11th 06 04:24 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


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