View Single Post
  #1   Report Post  
Posted to microsoft.public.excel.programming
Steph[_3_] Steph[_3_] is offline
external usenet poster
 
Posts: 312
Default Test if Sheet Exists - Tom Ogilvy

Hi Tom,

Remember last night you modified some code for me to include a message box
for files that did not contain the sheet "timesheet" (code below). Is it
possible to write the files that do not have that sheet to a log (maybe a
text file, or even the immediate window) as well as the message box? I was
hoping to add some code that would kick off this procedure automatically,
and didn't want the message box to hold up the procedure waiting for the ok
click.

Thanks in advance!


Sub OpenFiles_New()
'Opens Files in Folder

Dim GetFiles As Variant
Dim iFiles As Long
Dim nFiles As Long
Dim wkbk As Workbook
Dim sh As Worksheet

Application.ScreenUpdating = False
Application.DisplayAlerts = False
GetFiles = Application.GetOpenFilename _
(FileFilter:="Text Files (*.*),*.*", _
Title:="Select Timesheets to Include in SAP PO Upload",
MultiSelect:=True)
If TypeName(GetFiles) = "Boolean" Then
MsgBox "No Files Selected", vbOKOnly, "Nothing Selected"
End
Else
For iFiles = LBound(GetFiles) To UBound(GetFiles)
Workbooks.OpenText Filename:=GetFiles(iFiles)
Set wkbk = ActiveWorkbook

Set sh = Nothing
On Error Resume Next
Set sh = wkbk.Worksheets("TSData")
On Error Resume Next
If Not sh Is Nothing Then

' With ActiveWorkbook.Sheets("Timesheet").UsedRange
' .Value = .Value
' End With

wkbk.Sheets("TSData").Range("A10:AG" & _
Sheets("Timesheet").Range("A20").End(xlUp).Row).Co py
ThisWorkbook.Worksheets("Consol").Range("A" & _
Consol.Range("E65536").End(xlUp).Offset(1, 0).Row).PasteSpecial
_
Paste:=xlPasteValues
Else
MsgBox wkbk.Name & " does not have the TSData sheet"
End If
wkbk.Close
Next iFiles
End If

'**********************
'Duplicate Test Here

Application.ScreenUpdating = True
Application.DisplayAlerts = True

End Sub