george hart
Board Regular
- Joined
- Dec 4, 2008
- Messages
- 241
I need to open certain files according to the date within the file name and copy certain tabs: e.g: DyChrt2060711.xls
If I omit dte and the inputbox and just want to get DyChrt2.xls it works fine, but I need the option for one to enter the date to get the right file.
The code below appear to do nothing????
Dim wbOpen As Workbook
Dim wbNew As Workbook
'Change Path
Const strPath As String = "C:\Documents and Settings\HartG\My Documents\Dave Slater\"
Dim strExtension As String
Dte = InputBox("Enter the date")
ChDrive strPath
ChDir strPath
'Change extension
strExtension = Dir("DyChrt2 & dte & .xls")
Dim Tabs As Variant
Tabs = Array("LAIRA STOP", "LANDORE", "SPM", "OOC STOP")
Do While strExtension <> ""
Set wbOpen = Workbooks.Open(strPath & strExtension, UpdateLinks:=0)
With wbOpen
.Sheets(Tabs).Copy After:=ThisWorkbook.Sheets(1)
.Close SaveChanges:=False
End With
strExtension = Dir
Loop
End Sub
Any help would be most appreciated
If I omit dte and the inputbox and just want to get DyChrt2.xls it works fine, but I need the option for one to enter the date to get the right file.
The code below appear to do nothing????
Dim wbOpen As Workbook
Dim wbNew As Workbook
'Change Path
Const strPath As String = "C:\Documents and Settings\HartG\My Documents\Dave Slater\"
Dim strExtension As String
Dte = InputBox("Enter the date")
ChDrive strPath
ChDir strPath
'Change extension
strExtension = Dir("DyChrt2 & dte & .xls")
Dim Tabs As Variant
Tabs = Array("LAIRA STOP", "LANDORE", "SPM", "OOC STOP")
Do While strExtension <> ""
Set wbOpen = Workbooks.Open(strPath & strExtension, UpdateLinks:=0)
With wbOpen
.Sheets(Tabs).Copy After:=ThisWorkbook.Sheets(1)
.Close SaveChanges:=False
End With
strExtension = Dir
Loop
End Sub
Any help would be most appreciated