Home |
Search |
Today's Posts |
|
#1
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
Hi
I have the following problem in excel VBA: I need to open a file with the name run1mmyyyy. For example it must be opened for the months november 2006 to february 2007 How can I determine in vba code how many files must be open. Because febr.2007 is the second month and november2006 the 11th. Hope it's clear what I want en hope you can help. Best regards Jan |
#2
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
Try something like this:
Sub Test() Dim Date1 As Variant Dim Date2 As Variant Dim sDate As String Date1 = DateSerial(2006, 11, 1) Date2 = DateSerial(2007, 2, 1) sDate = WorksheetFunction.Text(Date1, "mmyyyy") filepath = "C://myfilepath/" Do While Date1 < Date2 Filename = filepath & "run1" & sDate & ".xls" Debug.Print Filename On Error Resume Next Workbooks.Open (Filename) On Error GoTo 0 Date1 = DateSerial(Year(Date1), Month(Date1) + 1, Day(Date1)) sDate = WorksheetFunction.Text(Date1, "mmyyyy") Debug.Print Date1, Date2 Loop End Sub "jan" wrote: Hi I have the following problem in excel VBA: I need to open a file with the name run1mmyyyy. For example it must be opened for the months november 2006 to february 2007 How can I determine in vba code how many files must be open. Because febr.2007 is the second month and november2006 the 11th. Hope it's clear what I want en hope you can help. Best regards Jan |
Reply |
Thread Tools | Search this Thread |
Display Modes | |
|
|
![]() |
||||
Thread | Forum | |||
Can I set a file to auto-open and save at each month begin date? | Excel Discussion (Misc queries) | |||
In Excel - Use Windows Explorer instead of File Open to open file | Excel Discussion (Misc queries) | |||
Open workbook macro- find correct month to open? | Excel Programming | |||
Open a file do a macro ( made) and open next succesive file | Excel Programming | |||
Open File or Switch Between Windows if File is Open | Excel Programming |