Home |
Search |
Today's Posts |
#1
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
I have a subroutine (macro) that automatically pulls data from various
workbooks. I would like to auto close each workbook when I am done extracting the data. The vba code to do this according to Excel help is: Workbooks("BOOK1.XLS").Close SaveChanges:=False The code works when I specify the name such as "BOOK1.XLS" . The problem is that the file names vary depending on dates etc. So I assign a variable to identify the names each time it is passed through the loop and incremented. Therefore the name of each stays the same through a string variable named "path3" as follows: While LDR <= DOM Workbooks.Open Filename:=path3 ' extract Selection.RemoveSubtotal Range("A2:O2").Select Range(Selection, Selection.End(xlDown)).Select Selection.Copy Windows("RwMTD.xls").Activate Sheets("MTD Data").Select Range("A1").Select Selection.End(xlDown).Select ActiveSheet.Paste Range("A1").Select ' This would be the point at which I would want to close the (Path3) file ' LDR Value LDR = LDR + 1 If LDR < 0 Or LDR 31 Then MsgBox ("Please enter a valid number for the day of month i.e.(1-31)") End Else If LDR 0 And LDR < 10 Then LDR = "0" & LDR Else LDR = LDR End If End If path2 = "\rpt." & Year & "." & month2 & "." & LDR & ".xls" path3 = path1 & path2 ' end extract Wend |
Thread Tools | Search this Thread |
Display Modes | |
|
|
![]() |
||||
Thread | Forum | |||
Auto save and close | Excel Worksheet Functions | |||
Auto Open, Refresh, Save, Close | Excel Discussion (Misc queries) | |||
Auto-save worksheet on close? | Excel Discussion (Misc queries) | |||
Auto Close Excel Workbook | Excel Programming | |||
Auto Close and Save | Excel Programming |