View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.programming
Barb Reinhardt Barb Reinhardt is offline
external usenet poster
 
Posts: 3,355
Default Open a file for every month

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