Google Answers Logo
View Question
 
Q: Opening a file that is already opened and not get a message saying so. Excel. ( Answered 4 out of 5 stars,   2 Comments )
Question  
Subject: Opening a file that is already opened and not get a message saying so. Excel.
Category: Computers > Programming
Asked by: dennyll40-ga
List Price: $15.00
Posted: 27 Sep 2002 00:21 PDT
Expires: 27 Oct 2002 00:21 PDT
Question ID: 69627
I am using Excel 2000.   (Alain and Denis.xls) has a macro(Sub
Auto_Open), that
opens (Cogenlog.xls) , I close (Alain and Denis.xls), then in Explorer
I doubleclick (Alain and Denis.xls). This time I get a message saying
that (Cogenlog.xls) is already opened. I don't want to see this
message. I know it is possible to NOT get this message. Even thow the
file is already opened, I simply want Excel to show me (Cogenlog.xls).
I have done it before but I don't know how.

Sub Auto_Open()
'
' Cogen Macro
' Macro recorded 29/07/2002 by Denis Lefebvre
'
' Keyboard Shortcut: Ctrl+c
'
   Workbooks.Open Filename:="COGENLOG.XLS"
   Windows("COGENLOG.XLS").Activate
    Sheets("Log").Select
    Range("A1").Select
    Selection.EntireRow.Insert
    
   Windows("Alain and Denis.xls").Activate
    Sheets("Stats").Select
    Range("A1:B1").Select
    Selection.Copy
    
   Windows("COGENLOG.XLS").Activate
    Sheets("Log").Select
    Range("A1").Select
    Selection.PasteSpecial Paste:=xlValues, Operation:=xlNone,
SkipBlanks:= _
        False, Transpose:=False
    ActiveWorkbook.Save
    
    
   Windows("Alain and Denis.xls").Activate
   ActiveWorkbook.Save
   If Worksheets("Stats").Range("C2") = "on" Then Application.Quit
    
End Sub
Answer  
Subject: Re: Opening a file that is already opened and not get a message saying so. Excel.
Answered By: bookface-ga on 01 Oct 2002 12:54 PDT
Rated:4 out of 5 stars
 
Sub Auto_Open()
'
' Cogen Macro
' Macro recorded 29/07/2002 by Denis Lefebvre
'
' Keyboard Shortcut: Ctrl+c
'
On Error GoTo OpenFile                  ' Prevents error message, if
not open.
Windows("COGENLOG.XLS").Activate        ' Tries to activate workbook,
if open.
On Error GoTo 0                         ' Restores normal error
handling
GoTo NextPart                           ' Skip over opening file if
                                        ' successfully switched
window.

OpenFile:                               ' Should only happen if not
open.
Workbooks.Open Filename:="COGENLOG.XLS" ' Opens the workbook.

NextPart:                               ' Continue the program
activity.
   Windows("COGENLOG.XLS").Activate
    Sheets("Log").Select
    Range("A1").Select
    Selection.EntireRow.Insert
     
   Windows("Alain and Denis.xls").Activate
    Sheets("Stats").Select
    Range("A1:B1").Select
    Selection.Copy
     
   Windows("COGENLOG.XLS").Activate
    Sheets("Log").Select
    Range("A1").Select
    Selection.PasteSpecial Paste:=xlValues, Operation:=xlNone, _
      SkipBlanks:=False, Transpose:=False
    ActiveWorkbook.Save
     
     
   Windows("Alain and Denis.xls").Activate
   ActiveWorkbook.Save
   If Worksheets("Stats").Range("C2") = "on" Then Application.Quit
     
End Sub

This way is a little quirky and hacky, but it works without any
issues.
I could probably find a better way at doing this if I had access to
Excel's Visual Basic help file, but I think this satisfies your needs.

Hope this is what you wanted.

- bookface

Clarification of Answer by bookface-ga on 01 Oct 2002 12:58 PDT
Let's try that again, so that you can copy and paste... apparently the
lines are broken down at 70 characters instead of 80.

Also, you should note that doing an "on error" handler for opening the
file will not bypass the message about the file being open already, as
it is a dialog box with multiple options.

Sub Auto_Open()
'
' Cogen Macro
' Macro recorded 29/07/2002 by Denis Lefebvre
'
' Keyboard Shortcut: Ctrl+c
'
On Error GoTo OpenFile
Windows("COGENLOG.XLS").Activate
On Error GoTo 0 'resume normal error activity
GoTo NextPart

OpenFile:
Workbooks.Open Filename:="COGENLOG.XLS"

NextPart:
   Windows("COGENLOG.XLS").Activate
    Sheets("Log").Select
    Range("A1").Select
    Selection.EntireRow.Insert
     
   Windows("Alain and Denis.xls").Activate
    Sheets("Stats").Select
    Range("A1:B1").Select
    Selection.Copy
     
   Windows("COGENLOG.XLS").Activate
    Sheets("Log").Select
    Range("A1").Select
    Selection.PasteSpecial Paste:=xlValues, Operation:=xlNone, _
      SkipBlanks:=False, Transpose:=False
    ActiveWorkbook.Save
     
     
   Windows("Alain and Denis.xls").Activate
   ActiveWorkbook.Save
   If Worksheets("Stats").Range("C2") = "on" Then Application.Quit
     
End Sub

Request for Answer Clarification by dennyll40-ga on 03 Oct 2002 19:48 PDT
Thank you so much. Now could you tell me why my macro works without
the lines you've added? It works with the two files that I have
mentioned. It is when I tried to recreate this with two new files by
copying the macro, (copy and paste), or typing it by hand, or using
the macro "record" feature of Excel that I cannot get this to work
again. Strange? I am doing the exact same thing with these two new
files and it won't work anymore?? There must be a setting that I
changed when I did the "Alain and Denis.xls" & "cogenlog.xls". If only
I could send you the two files so you could examine them. It is such a
simple macro. Anyways, thanks again. I just wish I knew what is
different in those files. Bye for now. Denis.

Request for Answer Clarification by dennyll40-ga on 03 Oct 2002 19:51 PDT
Thank you so much. Now could you tell me why my macro works without
the lines you've added? It works with the two files that I have
mentioned. It is when I tried to recreate this with two new files by
copying the macro, (copy and paste, of course changing the filenames
to the new ones), or typing it by hand, or using the macro "record"
feature of Excel that I cannot get this to work again. Strange? I am
doing the exact same thing with these two new files and it won't work
anymore?? There must be a setting that I changed when I did the "Alain
and Denis.xls" & "cogenlog.xls". If only I could send you the two
files so you could examine them. It is such a simple macro. Anyways,
thanks again. I just wish I knew what is different in those files. Bye
for now. Denis.

Clarification of Answer by bookface-ga on 03 Oct 2002 19:53 PDT
And you're using the same computer for both files?

I suspect it might be the operating system, or the version of Excel.
dennyll40-ga rated this answer:4 out of 5 stars
I am satisfied with the answer. I kept it simple because it's my first
question here at Google. I should have given more details and that is
why I am asking further information to my original question.

Comments  
Subject: Re: Opening a file that is already opened and not get a message saying so. Excel.
From: jrothlis-ga on 27 Sep 2002 15:26 PDT
 
I didn't realise I had to be a Google approved Researcher to answer
questions. Has this always been the case or has the policy changed
recently? I thought the whole point was that the "community" itself
sorted out the chaff from the wheat. It is very frustrating to see a
question right in front of me that I can very easily answer, but am
unable to because of Google's policy. =(
Subject: Re: Opening a file that is already opened and not get a message saying so. Excel.
From: ozguru-ga on 29 Sep 2002 15:43 PDT
 
Dear jrothlis,

Anyone is most welcome to contribute... I believe that is the main
purpose of the comment function.

Regards,

Important Disclaimer: Answers and comments provided on Google Answers are general information, and are not intended to substitute for informed professional medical, psychiatric, psychological, tax, legal, investment, accounting, or other professional advice. Google does not endorse, and expressly disclaims liability for any product, manufacturer, distributor, service or service provider mentioned or any opinion expressed in answers or comments. Please read carefully the Google Answers Terms of Service.

If you feel that you have found inappropriate content, please let us know by emailing us at answers-support@google.com with the question ID listed above. Thank you.
Search Google Answers for
Google Answers  


Google Home - Answers FAQ - Terms of Service - Privacy Policy