Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 181
Default 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.
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 181
Default 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.

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 21
Default Open file validation

Does this simple solution work?

Set WB = Workbooks.Open(FileName)
On Error Resume Next
WB.Save
If Err.Number = 1004 Then

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 181
Default 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

  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 181
Default 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



  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 21
Default 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

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 file validation Alberto Ast[_2_] Excel Programming 2 October 26th 09 04:38 AM
In Excel - Use Windows Explorer instead of File Open to open file KymY Excel Discussion (Misc queries) 1 August 5th 06 09:59 PM
Open a file do a macro ( made) and open next succesive file SVTman74 Excel Programming 5 April 21st 06 10:14 PM
Open File or Switch Between Windows if File is Open Ricky Pang Excel Programming 2 July 8th 05 05:51 AM
Open File or Switch Between Windows if File is Open Ricky Pang Excel Programming 0 July 2nd 05 08:41 PM


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