Home |
Search |
Today's Posts |
|
#1
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
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. |
#2
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
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. |
#3
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
Does this simple solution work?
Set WB = Workbooks.Open(FileName) On Error Resume Next WB.Save If Err.Number = 1004 Then |
#4
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
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 |
#5
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
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 |
#6
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
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 |
Reply |
Thread Tools | Search this Thread |
Display Modes | |
|
|
![]() |
||||
Thread | Forum | |||
open file validation | Excel Programming | |||
In Excel - Use Windows Explorer instead of File Open to open file | Excel Discussion (Misc queries) | |||
Open a file do a macro ( made) and open next succesive file | Excel Programming | |||
Open File or Switch Between Windows if File is Open | Excel Programming | |||
Open File or Switch Between Windows if File is Open | Excel Programming |