![]() |
Open file validation
I am opening a file with macros but some times the file is open by other
users and then my macro fails... how can I avoid the macro to fail if the file is open? I do not want it to ask me if I want to open as ready only... I would like to be able by program to know I could not open it and then procedd to do something else. What do I need to do? Thanks. |
Open file validation
I did some testing and it will open the file as read only and do not show any
error but while saving the file with the macro it goes to the "save as" screen because can not save under same name because it was opened as read only. How can I validate this? "Alberto Ast" wrote: I am opening a file with macros but some times the file is open by other users and then my macro fails... how can I avoid the macro to fail if the file is open? I do not want it to ask me if I want to open as ready only... I would like to be able by program to know I could not open it and then procedd to do something else. What do I need to do? Thanks. |
Open file validation
Does this simple solution work?
Set WB = Workbooks.Open(FileName) On Error Resume Next WB.Save If Err.Number = 1004 Then |
Open file validation
thanks but not sure how to structure the whole macro...
will set WB= workbook.open(Fielname) check for file status? "Stefano" wrote: Does this simple solution work? Set WB = Workbooks.Open(FileName) On Error Resume Next WB.Save If Err.Number = 1004 Then |
Open file validation
Have been doing some testing... I got to see the 1004 error... I think I am
close to make it work... but still since the file was open as read only while tring to save it, it ask me if I want to replace it... I would like not to be ask so I can procedd without saving... "Stefano" wrote: Does this simple solution work? Set WB = Workbooks.Open(FileName) On Error Resume Next WB.Save If Err.Number = 1004 Then |
Open file validation
The On Error Resume Next before the WB.Save should prevent any message from
showing up. If the file is not read only then it does save (I is not nice to waste time in a useless save overwriting a file just for a test, but it's good if it works for you.) If the file is read only then it fails, sets Err.Number to 1004, and you can decide what to do next. Set WB = Workbooks.Open(FileName) On Error Resume Next WB.Save IsReadOnly = 1004 = Err.Number On Error Goto 0 If IsReadOnly Then "Alberto Ast" wrote: Have been doing some testing... I got to see the 1004 error... I think I am close to make it work... but still since the file was open as read only while tring to save it, it ask me if I want to replace it... I would like not to be ask so I can procedd without saving... "Stefano" wrote: Does this simple solution work? Set WB = Workbooks.Open(FileName) On Error Resume Next WB.Save If Err.Number = 1004 Then |
All times are GMT +1. The time now is 12:15 PM. |
Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com