+ Reply to Thread
Results 1 to 7 of 7

Prevent opening a copy Workbook if already open

  1. #1
    Forum Contributor
    Join Date
    08-19-2009
    Location
    Netherlands, Amsterdam
    MS-Off Ver
    Excel 2010
    Posts
    585

    Prevent opening a copy Workbook if already open

    Hello all,

    The following code allows me to save the body of an email to an excel workbook.
    It works great but has a problem if the excel workbook is already open. (it opens a copy of the same workbook)

    Is it possible to prevent opening a copy of the same workbook but just add the new mail to it while already open?

    Please Login or Register  to view this content.

  2. #2
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,643

    Re: Prevent opening a copy Workbook if already open

    Why does the code open the same workbook twice?
    If posting code please use code tags, see here.

  3. #3
    Forum Contributor
    Join Date
    08-19-2009
    Location
    Netherlands, Amsterdam
    MS-Off Ver
    Excel 2010
    Posts
    585
    Quote Originally Posted by Norie View Post
    Why does the code open the same workbook twice?
    Guess because of this part

    xlApp.Workbooks.Open "\\test\Desktop\MSG.xlsm"

    But how do İ prevent this and let it know that it is already open

  4. #4
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,643

    Re: Prevent opening a copy Workbook if already open

    I'm a little confused, the posted code opens the same workbook twice.

    If you don't want that to happen remove the first line that opens the workbook.

    Also, why not close the workbook at the end of the code?

  5. #5
    Forum Contributor
    Join Date
    08-19-2009
    Location
    Netherlands, Amsterdam
    MS-Off Ver
    Excel 2010
    Posts
    585

    Re: Prevent opening a copy Workbook if already open

    İ like it open so the user sees that it went well. There is also the possibility that the user opened it before hitting the button.

  6. #6
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,643

    Re: Prevent opening a copy Workbook if already open

    Try this.
    Please Login or Register  to view this content.

  7. #7
    Forum Contributor
    Join Date
    08-19-2009
    Location
    Netherlands, Amsterdam
    MS-Off Ver
    Excel 2010
    Posts
    585

    Re: Prevent opening a copy Workbook if already open

    Hi Norie, thank you for trying!

    Running the code while the workbook is already open produces the following message:
    MSG.xlsm is already open. Reopening will cause....

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Prevent Auto Calculation On Opening a Workbook
    By Excel-Access in forum Excel General
    Replies: 1
    Last Post: 09-30-2015, 08:05 AM
  2. Prevent a workbook opening in Read Only
    By sambo24 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 07-01-2015, 07:25 AM
  3. [SOLVED] Prevent workbook from opening in new instnace
    By Brian Drozd in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 06-08-2015, 10:23 AM
  4. Prevent Open Resource Pool Dialogue box when opening MPP Project File using VBA
    By mond007 in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 01-17-2014, 08:14 AM
  5. Replies: 2
    Last Post: 08-21-2013, 10:00 AM
  6. Prevent excel from Opening with a new workbook
    By jerrydixon in forum Excel General
    Replies: 1
    Last Post: 08-14-2008, 03:24 PM
  7. How to prevent a 'copy' from opening
    By phil in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 01-22-2005, 03:06 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1