#1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 10
Default Logic

I have 30 excel workbooks for each year, say year 6,7 and 8, so in total 90
workbooks. Each of the workbooks are stored in this pathname ending in the
year for instance for Year 6 it would be this :-
\\SVR-SBS\FolderName\Folder6

I want to write a Macro to be able to open all the workbooks for one year
where an InputBox asks me which year I need and the answer then causes the
macro to open all 30 workbooks in whatever year I want.

Firstly, is there a way I can list the names of all the workbooks and
secondly if I cant, how do I write code that will only go through the list
of files once, based on the path obtained from the InputBox?

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 9,101
Default Logic

Sub getbooks()

folder = "\\SVR-SBS\FolderName\Folder"
Response = InputBox("Enter Year : ")
If Response < "" Then
folder = folder & Response & "\"
FName = Dir(folder & "*.xls")
Do While FName < ""
Set bk = Workbooks.Open(filename:=folder & FName)
'enter your code here


bk.Close savechanges:=False
FName = Dir()
Loop
Else
MsgBox ("Cannot OPen the year - Exiting Sub")
End If

End Sub


"MurrayB" wrote:

I have 30 excel workbooks for each year, say year 6,7 and 8, so in total 90
workbooks. Each of the workbooks are stored in this pathname ending in the
year for instance for Year 6 it would be this :-
\\SVR-SBS\FolderName\Folder6

I want to write a Macro to be able to open all the workbooks for one year
where an InputBox asks me which year I need and the answer then causes the
macro to open all 30 workbooks in whatever year I want.

Firstly, is there a way I can list the names of all the workbooks and
secondly if I cant, how do I write code that will only go through the list
of files once, based on the path obtained from the InputBox?


  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 10
Default Logic

Thanks Joel - I will give it a try!!


"Joel" wrote in message
...
Sub getbooks()

folder = "\\SVR-SBS\FolderName\Folder"
Response = InputBox("Enter Year : ")
If Response < "" Then
folder = folder & Response & "\"
FName = Dir(folder & "*.xls")
Do While FName < ""
Set bk = Workbooks.Open(filename:=folder & FName)
'enter your code here


bk.Close savechanges:=False
FName = Dir()
Loop
Else
MsgBox ("Cannot OPen the year - Exiting Sub")
End If

End Sub


"MurrayB" wrote:

I have 30 excel workbooks for each year, say year 6,7 and 8, so in total
90
workbooks. Each of the workbooks are stored in this pathname ending in
the
year for instance for Year 6 it would be this :-
\\SVR-SBS\FolderName\Folder6

I want to write a Macro to be able to open all the workbooks for one year
where an InputBox asks me which year I need and the answer then causes
the
macro to open all 30 workbooks in whatever year I want.

Firstly, is there a way I can list the names of all the workbooks and
secondly if I cant, how do I write code that will only go through the
list
of files once, based on the path obtained from the InputBox?



  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,934
Default Logic

To open all workbooks in the specified folder number, give this a try...

Sub OpenWorkbooks()
Dim Path As String
Dim Answer As String
Dim FileName As String
Answer = InputBox("Please enter folder number...")
If IsNumeric(Answer) Then
' Note: Do not put trailing backslash on path
Path = "\\SVR-SBS\FolderName\Folder"
FileName = Dir(Path & "\" & Answer & ".xls")
Do While Len(FileName) 0
Application.Workbooks.Open Path & FileName
FileName = Dir
Loop
End If
End Sub

--
Rick (MVP - Excel)


"MurrayB" wrote in message
...
I have 30 excel workbooks for each year, say year 6,7 and 8, so in total 90
workbooks. Each of the workbooks are stored in this pathname ending in the
year for instance for Year 6 it would be this :-
\\SVR-SBS\FolderName\Folder6

I want to write a Macro to be able to open all the workbooks for one year
where an InputBox asks me which year I need and the answer then causes the
macro to open all 30 workbooks in whatever year I want.

Firstly, is there a way I can list the names of all the workbooks and
secondly if I cant, how do I write code that will only go through the list
of files once, based on the path obtained from the InputBox?


  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 10
Default Logic

Thanks Nick - will give it a shot!


"Rick Rothstein" wrote in message
...
To open all workbooks in the specified folder number, give this a try...

Sub OpenWorkbooks()
Dim Path As String
Dim Answer As String
Dim FileName As String
Answer = InputBox("Please enter folder number...")
If IsNumeric(Answer) Then
' Note: Do not put trailing backslash on path
Path = "\\SVR-SBS\FolderName\Folder"
FileName = Dir(Path & "\" & Answer & ".xls")
Do While Len(FileName) 0
Application.Workbooks.Open Path & FileName
FileName = Dir
Loop
End If
End Sub

--
Rick (MVP - Excel)


"MurrayB" wrote in message
...
I have 30 excel workbooks for each year, say year 6,7 and 8, so in total
90 workbooks. Each of the workbooks are stored in this pathname ending in
the year for instance for Year 6 it would be this :-
\\SVR-SBS\FolderName\Folder6

I want to write a Macro to be able to open all the workbooks for one year
where an InputBox asks me which year I need and the answer then causes
the macro to open all 30 workbooks in whatever year I want.

Firstly, is there a way I can list the names of all the workbooks and
secondly if I cant, how do I write code that will only go through the
list of files once, based on the path obtained from the InputBox?





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
More if then logic DJ Excel Worksheet Functions 2 October 8th 09 05:40 PM
If Then Logic RPB Excel Worksheet Functions 5 July 31st 09 12:41 AM
LOGIC H0MELY Excel Discussion (Misc queries) 6 June 4th 08 10:41 PM
If Then logic not enough workerbeeVAB Excel Discussion (Misc queries) 4 January 5th 06 05:24 PM
IRR Logic Carrie Excel Worksheet Functions 2 November 18th 05 08:59 PM


All times are GMT +1. The time now is 04:09 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"