![]() |
Check if file Is Accessible
Hi
i'm looking to improve my excel macro's... i've have a few macros that require other xls/csv files to be opened... my question is. How do i check if the user has access to the required folder? I would like a message box Specifically for the Folder is not accessible call IS to lift Restriction etc... my guess is some sort of DLL file is required but i'm unsure any help would be much appreciated... z |
Check if file Is Accessible
You can try to open the file and check for an error. Check out the help for
"On Error". Here's one way: dim WB as workbook On Error Resume Next set wb=workbooks.Open(<pathandfilename) If err.number0 then msgbox err.description 'Do something about the error end if NickHK "zimitry" wrote in message ... Hi i'm looking to improve my excel macro's... i've have a few macros that require other xls/csv files to be opened... my question is. How do i check if the user has access to the required folder? I would like a message box Specifically for the Folder is not accessible call IS to lift Restriction etc... my guess is some sort of DLL file is required but i'm unsure any help would be much appreciated... z |
Check if file Is Accessible
Nick:
2 Questions; OP was interested in seeing if a Folder was accessible, but I see you used pathandfilename <<filename?? Is that OK? Also your line "On Error Resume Next" says to me that if Excel when asked to set WB = something it can't find it.. Then IGNORE the error and continue on. Perhaps (in the background though) an err is generated and it is your If stat which is jumping in to Provide the message. Is this the case? Thanks, Jim "NickHK" wrote in message : You can try to open the file and check for an error. Check out the help for "On Error". Here's one way: dim WB as workbook On Error Resume Next set wb=workbooks.Open(<pathandfilename) If err.number0 then msgbox err.description 'Do something about the error end if NickHK "zimitry" wrote in message ... Hi i'm looking to improve my excel macro's... i've have a few macros that require other xls/csv files to be opened... my question is. How do i check if the user has access to the required folder? I would like a message box Specifically for the Folder is not accessible call IS to lift Restriction etc... my guess is some sort of DLL file is required but i'm unsure any help would be much appreciated... z |
Check if file Is Accessible
Jim,
Well, the OP stated "that require other xls/csv files to be opened". Just seemed easier to attempt the main aim of the code (opening files) rather than an inferior aim (testing for access). Without the access you cannot open, but even with access it does not necessarily mean you can open. If you do handle the (potential) error in some way, the code will crash. Like this, we first check if there was actually an error and if so do something about it, possibly abort. NickHK "JMay" wrote in message ... Nick: 2 Questions; OP was interested in seeing if a Folder was accessible, but I see you used pathandfilename <<filename?? Is that OK? Also your line "On Error Resume Next" says to me that if Excel when asked to set WB = something it can't find it.. Then IGNORE the error and continue on. Perhaps (in the background though) an err is generated and it is your If stat which is jumping in to Provide the message. Is this the case? Thanks, Jim "NickHK" wrote in message : You can try to open the file and check for an error. Check out the help for "On Error". Here's one way: dim WB as workbook On Error Resume Next set wb=workbooks.Open(<pathandfilename) If err.number0 then msgbox err.description 'Do something about the error end if NickHK "zimitry" wrote in message ... Hi i'm looking to improve my excel macro's... i've have a few macros that require other xls/csv files to be opened... my question is. How do i check if the user has access to the required folder? I would like a message box Specifically for the Folder is not accessible call IS to lift Restriction etc... my guess is some sort of DLL file is required but i'm unsure any help would be much appreciated... z |
Check if file Is Accessible
Thanks NickHK - much appreciated your explanation
Jim "NickHK" wrote in message : Jim, Well, the OP stated "that require other xls/csv files to be opened". Just seemed easier to attempt the main aim of the code (opening files) rather than an inferior aim (testing for access). Without the access you cannot open, but even with access it does not necessarily mean you can open. If you do handle the (potential) error in some way, the code will crash. Like this, we first check if there was actually an error and if so do something about it, possibly abort. NickHK "JMay" wrote in message ... Nick: 2 Questions; OP was interested in seeing if a Folder was accessible, but I see you used pathandfilename <<filename?? Is that OK? Also your line "On Error Resume Next" says to me that if Excel when asked to set WB = something it can't find it.. Then IGNORE the error and continue on. Perhaps (in the background though) an err is generated and it is your If stat which is jumping in to Provide the message. Is this the case? Thanks, Jim "NickHK" wrote in message : You can try to open the file and check for an error. Check out the help for "On Error". Here's one way: dim WB as workbook On Error Resume Next set wb=workbooks.Open(<pathandfilename) If err.number0 then msgbox err.description 'Do something about the error end if NickHK "zimitry" wrote in message ... Hi i'm looking to improve my excel macro's... i've have a few macros that require other xls/csv files to be opened... my question is. How do i check if the user has access to the required folder? I would like a message box Specifically for the Folder is not accessible call IS to lift Restriction etc... my guess is some sort of DLL file is required but i'm unsure any help would be much appreciated... z |
All times are GMT +1. The time now is 12:17 AM. |
Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com