Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 57
Default Alerting user if file not open

Dear Wise Ones,

I am wanting to prompt users to open the required file if not already open.
There is some nearly-helpful answers in these posts, but I can't quite
achieve what I want.

This code of mine is useless because errorMsgs executes whether error or not.

Set rotaBk = Workbooks("EAA.xls")
rotaBk.Activate
On Error GoTo errorMsgs
errorMsgs:
MsgBox ("Open EAA.xls ")
Exit Sub


If I try to put a condition on error handling execution:

If error then
MsgBox ("Open EAA.xls " & error)
exit sub
end if

I get a "type mismatch" in the error MsgBox

As always, help most appreciated,

matilda
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,302
Default Alerting user if file not open

Hi Matilda,

Try something like:

'=============
Public Sub Tester()
Dim rotaBk As Workbook
Const myPath As String = "C\:Data\" '<<==== CHANGE

On Error Resume Next
Set rotaBk = Workbooks("EAA.xls")
On Error GoTo 0

If rotaBk Is Nothing Then
Set rotaBk = Workbooks.Open _
(Filename:=myPath & "EAA.xls")
End If
End Sub
'<<=============


---
Regards,
Norman



"Matilda" wrote in message
...
Dear Wise Ones,

I am wanting to prompt users to open the required file if not already
open.
There is some nearly-helpful answers in these posts, but I can't quite
achieve what I want.

This code of mine is useless because errorMsgs executes whether error or
not.

Set rotaBk = Workbooks("EAA.xls")
rotaBk.Activate
On Error GoTo errorMsgs
errorMsgs:
MsgBox ("Open EAA.xls ")
Exit Sub


If I try to put a condition on error handling execution:

If error then
MsgBox ("Open EAA.xls " & error)
exit sub
end if

I get a "type mismatch" in the error MsgBox

As always, help most appreciated,

matilda



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 57
Default Alerting user if file not open

Thanks for your suggestion, Norman.

I would adopt it word for word except that the path is not going to be
fixed, and the file can be in one of three folders (I have no control over
that)

Trying to help users all I can... all I can do is tell them that required
folders are not open at the outset, so they can go away, find the version
they want, open it and start again.

tried this:

On Error Resume Next
Set wbk = Workbooks("myFile.xls")
On Error Resume Next
wbk.Activate
On Error GoTo 0

If wbk Is Nothing Then
MsgBox ("Open myFile.xls and restart procedure ")
Exit Sub
End If

with the file open, and again with the file closed.
The error seems to be ignored and code resumes without the prompt if file
is actually closed.

Thanks for your patience,

Matilda



"Norman Jones" wrote:

Hi Matilda,

Try something like:

'=============
Public Sub Tester()
Dim rotaBk As Workbook
Const myPath As String = "C\:Data\" '<<==== CHANGE

On Error Resume Next
Set rotaBk = Workbooks("EAA.xls")
On Error GoTo 0

If rotaBk Is Nothing Then
Set rotaBk = Workbooks.Open _
(Filename:=myPath & "EAA.xls")
End If
End Sub
'<<=============


---
Regards,
Norman



"Matilda" wrote in message
...
Dear Wise Ones,

I am wanting to prompt users to open the required file if not already
open.
There is some nearly-helpful answers in these posts, but I can't quite
achieve what I want.

This code of mine is useless because errorMsgs executes whether error or
not.

Set rotaBk = Workbooks("EAA.xls")
rotaBk.Activate
On Error GoTo errorMsgs
errorMsgs:
MsgBox ("Open EAA.xls ")
Exit Sub


If I try to put a condition on error handling execution:

If error then
MsgBox ("Open EAA.xls " & error)
exit sub
end if

I get a "type mismatch" in the error MsgBox

As always, help most appreciated,

matilda




  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,302
Default Alerting user if file not open

Hi Matilda,

Perhaps try something like:
'=============
Public Sub Tester()
Dim rotaBk As Workbook
Dim FName As Variant
Const myPath As String = "C\:Data\" '<<==== CHANGE

On Error Resume Next
Set rotaBk = Workbooks("EAA.xls")
On Error GoTo 0

If rotaBk Is Nothing Then
FName = Application.GetOpenFilename( _
FileFilter:="File Excel (*.xls),*.xls", _
Title:="SelectFile")

If FName < False Then
Set rotaBk = Workbooks.Open(FName)
Else
MsgBox "No file selected!"
'do something?
End If
End If
End Sub
'<<=============



---
Regards,
Norman


"Matilda" wrote in message
...
Thanks for your suggestion, Norman.

I would adopt it word for word except that the path is not going to be
fixed, and the file can be in one of three folders (I have no control over
that)

Trying to help users all I can... all I can do is tell them that required
folders are not open at the outset, so they can go away, find the version
they want, open it and start again.

tried this:

On Error Resume Next
Set wbk = Workbooks("myFile.xls")
On Error Resume Next
wbk.Activate
On Error GoTo 0

If wbk Is Nothing Then
MsgBox ("Open myFile.xls and restart procedure ")
Exit Sub
End If

with the file open, and again with the file closed.
The error seems to be ignored and code resumes without the prompt if file
is actually closed.

Thanks for your patience,

Matilda



"Norman Jones" wrote:

Hi Matilda,

Try something like:

'=============
Public Sub Tester()
Dim rotaBk As Workbook
Const myPath As String = "C\:Data\" '<<==== CHANGE

On Error Resume Next
Set rotaBk = Workbooks("EAA.xls")
On Error GoTo 0

If rotaBk Is Nothing Then
Set rotaBk = Workbooks.Open _
(Filename:=myPath & "EAA.xls")
End If
End Sub
'<<=============


---
Regards,
Norman



"Matilda" wrote in message
...
Dear Wise Ones,

I am wanting to prompt users to open the required file if not already
open.
There is some nearly-helpful answers in these posts, but I can't quite
achieve what I want.

This code of mine is useless because errorMsgs executes whether error
or
not.

Set rotaBk = Workbooks("EAA.xls")
rotaBk.Activate
On Error GoTo errorMsgs
errorMsgs:
MsgBox ("Open EAA.xls ")
Exit Sub


If I try to put a condition on error handling execution:

If error then
MsgBox ("Open EAA.xls " & error)
exit sub
end if

I get a "type mismatch" in the error MsgBox

As always, help most appreciated,

matilda






  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,302
Default Alerting user if file not open

Hi Matilda,

Const myPath As String = "C\:Data\" '<<==== CHANGE


I should have deleted the above, now redundant, code line.


--
Regards,
Norman




  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 57
Default Alerting user if file not open

Hi Norman,

That's clever!

Opening the dialog for users to choose a file solves the problem, in a way I
hadn't thought of.

Many, many thanks.

Matilda

"Norman Jones" wrote:

Hi Matilda,

Const myPath As String = "C\:Data\" '<<==== CHANGE


I should have deleted the above, now redundant, code line.


--
Regards,
Norman



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
User replaces existing file with blank during file open sjs Excel Discussion (Misc queries) 3 August 18th 08 06:16 PM
File is already open by user X eagle13 Excel Discussion (Misc queries) 1 July 24th 06 01:14 PM
not being prompted that user has file open maryj Excel Discussion (Misc queries) 0 December 15th 05 03:10 PM
How to ask user for file to open Dwaine Horton Excel Programming 2 February 18th 04 07:48 AM


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