Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
PO PO is offline
external usenet poster
 
Posts: 66
Default Bulk processing

Hi!

Excel 2000.

I'm trying to create a .xlt which contains code that opens and processes all
..xls-files in a certain direktory on the users harddrive.
I need to write VBA looking something like this:


Dim xls as Excel.Workbook

For each xls in "Directory on Harddrive"
Open xls-file
Check for a certain value in xls
Close xls-file
Next


Any ideas on how to write this code?

TIA
PO


  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,758
Default Bulk processing

Something like this????

Option Explicit
Sub testme()

Dim myFiles() As String
Dim fCtr As Long
Dim myFile As String
Dim myPath As String
Dim wkbk As Workbook
Dim wks As Worksheet
Dim rptWks As Worksheet
Dim testWks As Worksheet
Dim oRow As Long

'change to point at the folder to check
myPath = "c:\my documents\excel\test"
If Right(myPath, 1) < "\" Then
myPath = myPath & "\"
End If

myFile = Dir(myPath & "*.xls")
If myFile = "" Then
MsgBox "no files found"
Exit Sub
End If

'get the list of files
fCtr = 0
Do While myFile < ""
fCtr = fCtr + 1
ReDim Preserve myFiles(1 To fCtr)
myFiles(fCtr) = myFile
myFile = Dir()
Loop

If fCtr 0 Then
Set rptWks = Workbooks.Add(1).Worksheets(1)
With rptWks
.Range("a1").Resize(1, 2).Value _
= Array("Name", "Found")
End With
oRow = 1
For fCtr = LBound(myFiles) To UBound(myFiles)
oRow = oRow + 1
Set wkbk = Workbooks.Open(myPath & myFiles(fCtr))

Set testWks = Nothing
On Error Resume Next
Set testWks = wkbk.Worksheets("sheet1")
On Error GoTo 0

With rptWks.Cells(oRow, "A")
.Value = myFiles(fCtr)
If testWks Is Nothing Then
.Offset(0, 1).Value = "Missing Sheet"
Else
If testWks.Range("a1").Value = "hi there" Then
.Offset(0, 1).Value = "Yes"
Else
.Offset(0, 1).Value = "No"
End If
End If
End With

wkbk.Close savechanges:=True
Next fCtr
End If

End Sub



PO wrote:

Hi!

Excel 2000.

I'm trying to create a .xlt which contains code that opens and processes all
.xls-files in a certain direktory on the users harddrive.
I need to write VBA looking something like this:

Dim xls as Excel.Workbook

For each xls in "Directory on Harddrive"
Open xls-file
Check for a certain value in xls
Close xls-file
Next

Any ideas on how to write this code?

TIA
PO


--

Dave Peterson
  #3   Report Post  
Posted to microsoft.public.excel.programming
PO PO is offline
external usenet poster
 
Posts: 66
Default Bulk processing

Thanks Dave!

Works just fine.

Regards
PO

"Dave Peterson" wrote in message
...
Something like this????

Option Explicit
Sub testme()

Dim myFiles() As String
Dim fCtr As Long
Dim myFile As String
Dim myPath As String
Dim wkbk As Workbook
Dim wks As Worksheet
Dim rptWks As Worksheet
Dim testWks As Worksheet
Dim oRow As Long

'change to point at the folder to check
myPath = "c:\my documents\excel\test"
If Right(myPath, 1) < "\" Then
myPath = myPath & "\"
End If

myFile = Dir(myPath & "*.xls")
If myFile = "" Then
MsgBox "no files found"
Exit Sub
End If

'get the list of files
fCtr = 0
Do While myFile < ""
fCtr = fCtr + 1
ReDim Preserve myFiles(1 To fCtr)
myFiles(fCtr) = myFile
myFile = Dir()
Loop

If fCtr 0 Then
Set rptWks = Workbooks.Add(1).Worksheets(1)
With rptWks
.Range("a1").Resize(1, 2).Value _
= Array("Name", "Found")
End With
oRow = 1
For fCtr = LBound(myFiles) To UBound(myFiles)
oRow = oRow + 1
Set wkbk = Workbooks.Open(myPath & myFiles(fCtr))

Set testWks = Nothing
On Error Resume Next
Set testWks = wkbk.Worksheets("sheet1")
On Error GoTo 0

With rptWks.Cells(oRow, "A")
.Value = myFiles(fCtr)
If testWks Is Nothing Then
.Offset(0, 1).Value = "Missing Sheet"
Else
If testWks.Range("a1").Value = "hi there" Then
.Offset(0, 1).Value = "Yes"
Else
.Offset(0, 1).Value = "No"
End If
End If
End With

wkbk.Close savechanges:=True
Next fCtr
End If

End Sub



PO wrote:

Hi!

Excel 2000.

I'm trying to create a .xlt which contains code that opens and processes

all
.xls-files in a certain direktory on the users harddrive.
I need to write VBA looking something like this:

Dim xls as Excel.Workbook

For each xls in "Directory on Harddrive"
Open xls-file
Check for a certain value in xls
Close xls-file
Next

Any ideas on how to write this code?

TIA
PO


--

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
bulk removal of hyperlinks Tim[_7_] Excel Discussion (Misc queries) 2 November 2nd 07 01:57 AM
Bulk vlookup? Sarah Excel Worksheet Functions 2 January 24th 07 08:12 PM
Editing fields in bulk bhola-bhala Excel Discussion (Misc queries) 2 April 1st 06 07:47 AM
Bulk row deletion quartz[_2_] Excel Programming 1 November 9th 04 05:00 PM
Bulk Email Don Kline[_3_] Excel Programming 1 August 31st 03 04:27 PM


All times are GMT +1. The time now is 02:58 AM.

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"