Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 390
Default Open Multiple Files At Once

I know this is easy and I hope I am close. I want to open several files from
different folders. I kow the names of the files so this is what I have.

Workbooks.Open Filename:="Y:\folder\filename.xlsm"

When I run the macro it says file not found. Do I have to use the following
to change folders each time I am using a different folder?

ChDir "Y:\folder"


  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Open Multiple Files At Once


hi Bill,


Bill;709607 Wrote:

I know this is easy and I hope I am close. I want to open several files
from
different folders. I kow the names of the files so this is what I

have.


VBA Code:
--------------------


Workbooks.Open Filename:="Y:\folder\filename.xlsm"
--------------------



When I run the macro it says file not found. Do I have to use the

following
to change folders each time I am using a different folder?


VBA Code:
--------------------


ChDir "Y:\folder"
--------------------






I don't think you should need to use ChDir (See SHG's comment 'here'
(http://tinyurl.com/2b2tdng)).

Is it possible that there are any spelling mistakes or extra spaces etc
in your file names?
As a matter of course I suggest testing for the file's existence before
performing any actions on it. Here's some an example function:


VBA Code:
--------------------


Public Function DoesFileFolderExist(strfullpath As String) As Boolean
'sourced from 'Function to Check if File or Directory (Folder) exists | Excelguru.ca' (http://www.excelguru.ca/node/30) by Ken Puls
'note it only checks for the existence of the lowest folder (or the file) in the strfullpath string.
If Not Dir(strfullpath, vbDirectory) = vbNullString Then DoesFileFolderExist = True
End Function
'this can be used in sub's as shown below...
sub test()
dim PathOfFileToOpen as string
PathOfFileToOpen = "Y:\folder\filename.xlsm"
if DoesFileFolderExist(PathOfFileToOpen) then
Workbooks.Open Filename:="Y:\folder\filename.xlsm"
else
msgbox "There is no file called " & PathOfFileToOpen
end if

--------------------




hth
Rob


--
broro183

Rob Brockett. Always learning & the best way to learn is to
experience...
------------------------------------------------------------------------
broro183's Profile: http://www.thecodecage.com/forumz/member.php?u=333
View this thread: http://www.thecodecage.com/forumz/sh...d.php?t=198609

http://www.thecodecage.com/forumz

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 390
Default Open Multiple Files At Once

Yes thank you - I went brain dead and had an extra [ in the line that messed
it up.

Thanks



"broro183" wrote:


hi Bill,



Bill;709607 Wrote:

I know this is easy and I hope I am close. I want to open several files
from
different folders. I kow the names of the files so this is what I

have.




VBA Code:
--------------------



Workbooks.Open Filename:="Y:\folder\filename.xlsm"


--------------------




When I run the macro it says file not found. Do I have to use the

following
to change folders each time I am using a different folder?




VBA Code:
--------------------



ChDir "Y:\folder"


--------------------







I don't think you should need to use ChDir (See SHG's comment 'here'
(http://tinyurl.com/2b2tdng)).

Is it possible that there are any spelling mistakes or extra spaces etc
in your file names?
As a matter of course I suggest testing for the file's existence before
performing any actions on it. Here's some an example function:



VBA Code:
--------------------



Public Function DoesFileFolderExist(strfullpath As String) As Boolean
'sourced from 'Function to Check if File or Directory (Folder) exists | Excelguru.ca' (http://www.excelguru.ca/node/30) by Ken Puls
'note it only checks for the existence of the lowest folder (or the file) in the strfullpath string.
If Not Dir(strfullpath, vbDirectory) = vbNullString Then DoesFileFolderExist = True
End Function
'this can be used in sub's as shown below...
sub test()
dim PathOfFileToOpen as string
PathOfFileToOpen = "Y:\folder\filename.xlsm"
if DoesFileFolderExist(PathOfFileToOpen) then
Workbooks.Open Filename:="Y:\folder\filename.xlsm"
else
msgbox "There is no file called " & PathOfFileToOpen
end if


--------------------




hth
Rob


--
broro183

Rob Brockett. Always learning & the best way to learn is to
experience...
------------------------------------------------------------------------
broro183's Profile: http://www.thecodecage.com/forumz/member.php?u=333
View this thread: http://www.thecodecage.com/forumz/sh...d.php?t=198609

http://www.thecodecage.com/forumz

.

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
Open Text Files/Format/Save as .xls for multiple files. Ray Excel Programming 9 June 9th 09 04:23 PM
Open multiple files J Setting up and Configuration of Excel 4 December 17th 07 05:30 PM
Evaluate Open Files / multiple instances open Troubled User Excel Programming 3 March 30th 07 03:48 AM
Open multiple files into multiple worksheets of the same workbook lil Matt Excel Discussion (Misc queries) 1 October 31st 06 09:03 PM
open multiple files Dennis S. Excel Discussion (Misc queries) 1 April 28th 06 05:10 PM


All times are GMT +1. The time now is 09:00 AM.

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"