Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
Jan Jan is offline
external usenet poster
 
Posts: 159
Default Open a file for every month

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   Report Post  
Posted to microsoft.public.excel.programming
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

Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Can I set a file to auto-open and save at each month begin date? Dominic Excel Discussion (Misc queries) 9 August 8th 09 05:57 PM
In Excel - Use Windows Explorer instead of File Open to open file KymY Excel Discussion (Misc queries) 1 August 5th 06 09:59 PM
Open workbook macro- find correct month to open? buzzharley[_10_] Excel Programming 8 July 8th 06 04:30 AM
Open a file do a macro ( made) and open next succesive file SVTman74 Excel Programming 5 April 21st 06 10:14 PM
Open File or Switch Between Windows if File is Open Ricky Pang Excel Programming 2 July 8th 05 05:51 AM


All times are GMT +1. The time now is 12:43 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"