Home |
Search |
Today's Posts |
|
#1
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
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
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
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
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
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
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
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
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
Hi Matilda,
Const myPath As String = "C\:Data\" '<<==== CHANGE I should have deleted the above, now redundant, code line. -- Regards, Norman |
#6
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
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 |
Display Modes | |
|
|
![]() |
||||
Thread | Forum | |||
User replaces existing file with blank during file open | Excel Discussion (Misc queries) | |||
File is already open by user X | Excel Discussion (Misc queries) | |||
not being prompted that user has file open | Excel Discussion (Misc queries) | |||
How to ask user for file to open | Excel Programming |