PC Review


Reply
Thread Tools Rate Thread

close/open workbook without prompts

 
 
HammerJoe@gmail.com
Guest
Posts: n/a
 
      28th Jun 2008
Hi,

I have a macro in my main workbook that creates a new workbook and it
copies from main workbook a report sheet and pastes only formats and
values to it so it can be emailed.

Because people can send it as an attachment, I decided to create a new
workbook with just one sheet. It makes the file smaller and at the
same time it removes the formulas from prying eyes.

The problem is I can't use the sendmail function, because it requires
saving the new workbook to the disk (as far as I know) and because of
profile space limitations this is not workable for me).

The other problem, when the workbook is created a button is created to
allow the user to close the workbook and return to the main workbook.
That works fine except when the email recipient opens the file.

there is a prompt about broken links (which is obviously because of
the button).
I understand that it is not possible to avoid that prompt with excel
2003

So I decided to get rid of the button and just wait for the new
workbook to be closed before returning to the main workbook and
continuing with the macro
Another problem then, excel of course prompts to save the new
workbook.


Can I eliminate the Broken/Update link prompt when opening the
workbook?

OR

How can I close the workbook without prompt??
(i am not sre if I can inject code from a macro into the new workbook
to detect close event??)






 
Reply With Quote
 
 
 
 
Noman
Guest
Posts: n/a
 
      28th Jun 2008
Try
Dim app As New Microsoft.Office.Interop.Excel.Application
app.DisplayAlerts = False
' Do your work
app.DisplayAlerts = True


"(E-Mail Removed)" wrote:

> Hi,
>
> I have a macro in my main workbook that creates a new workbook and it
> copies from main workbook a report sheet and pastes only formats and
> values to it so it can be emailed.
>
> Because people can send it as an attachment, I decided to create a new
> workbook with just one sheet. It makes the file smaller and at the
> same time it removes the formulas from prying eyes.
>
> The problem is I can't use the sendmail function, because it requires
> saving the new workbook to the disk (as far as I know) and because of
> profile space limitations this is not workable for me).
>
> The other problem, when the workbook is created a button is created to
> allow the user to close the workbook and return to the main workbook.
> That works fine except when the email recipient opens the file.
>
> there is a prompt about broken links (which is obviously because of
> the button).
> I understand that it is not possible to avoid that prompt with excel
> 2003
>
> So I decided to get rid of the button and just wait for the new
> workbook to be closed before returning to the main workbook and
> continuing with the macro
> Another problem then, excel of course prompts to save the new
> workbook.
>
>
> Can I eliminate the Broken/Update link prompt when opening the
> workbook?
>
> OR
>
> How can I close the workbook without prompt??
> (i am not sre if I can inject code from a macro into the new workbook
> to detect close event??)
>
>
>
>
>
>
>

 
Reply With Quote
 
HammerJoe@gmail.com
Guest
Posts: n/a
 
      28th Jun 2008
On Jun 28, 1:28*pm, Noman <No...@discussions.microsoft.com> wrote:
> Try
> Dim app As New Microsoft.Office.Interop.Excel.Application
> app.DisplayAlerts = False
> ' Do your work
> app.DisplayAlerts = True


Where do you put that?

This is a new workbook that is created by a macro using with the
Workbook.Add, so no code is added to the newly workbook.
When it is closed it doesnt call any events in the main workbook.
The only way I have found so far to detect that the new workbook has
been closed is during mainworkbook.activate procedure tries to put the
focus back to it and of course an error occurs and is trapped.

More sugestions or alternatives?
 
Reply With Quote
 
Doug Glancy
Guest
Posts: n/a
 
      29th Jun 2008
HammerJoe,

You could add code to the new workbook at runtime. See
http://www.cpearson.com/excel/vbe.aspx. I don't think I'd do it that way.

You could also just create an Excel template with the code in it and open it
like this:
Workbooks.Open (ThisWorkbook.Path & "\MyTemplate.xlt")
Of course then you'd be sending out a workbook with macros in it, but I
guess you could consult Chip's page above for how to remove it.

Here's one more possibility - in the code for your main workbook make a
class that "controls" the workbook. First, insert a class to your workbook
in the VBE. In the code module for that new class paste this code:

Option Explicit
Private WithEvents wbNewBook As Workbook
Private m_WB As Workbook

Private Sub Class_Terminate()
Set m_WB = Nothing
Set wbNewBook = Nothing
End Sub

Public Property Set Wb(PassedWb As Workbook)
Set m_WB = PassedWb
Set wbNewBook = m_WB
End Property

Public Property Get Wb() As Workbook
Set Wb = m_WB
End Property

Private Sub wbNewBook_BeforeClose(Cancel As Boolean)
Application.EnableEvents = False
m_WB.Close savechanges:=False
Workbooks("test.xls").Activate
Call ContinueOnOurMerryWay
Application.EnableEvents = True
Cancel = True
End Sub

Private Sub wbNewBook_BeforeSave(ByVal SaveAsUI As Boolean, Cancel As
Boolean)
MsgBox "Sorry, changes not allowed"
Cancel = True
End Sub

Private Sub wbNewBook_SheetSelectionChange(ByVal Sh As Object, ByVal Target
As Range)
'this is not necessary for your purposes
'but shows how this class captures all
'events in your new book, just fyi
MsgBox "selection change"
End Sub


Then add a regular module, which uses Class1. (You can rename the class
from the default of "Class1" to whatever you want.)

Option Explicit
Public NewBook As Class1

Sub StartTheBallRolling()

ThisWorkbook.Sheets(1).Copy
Set NewBook = New Class1
Set NewBook.Wb = ActiveWorkbook
End Sub

Sub ContinueOnOurMerryWay()
Set NewBook.Wb = Nothing
Set NewBook = Nothing
MsgBox "Continuing"
End Sub

My understanding is that you never want the user to save the workbook. If
that's not true then the above is wrong. If it's true, and you decide to go
the template route above, you can use the BeforeClose and BeforeSave code
above. Just change "m_WB.Close" to "ThisWorkBook.Close"

hth,

Doug

<(E-Mail Removed)> wrote in message
news:380355ab-1a0d-486c-ba3a-(E-Mail Removed)...
> Hi,
>
> I have a macro in my main workbook that creates a new workbook and it
> copies from main workbook a report sheet and pastes only formats and
> values to it so it can be emailed.
>
> Because people can send it as an attachment, I decided to create a new
> workbook with just one sheet. It makes the file smaller and at the
> same time it removes the formulas from prying eyes.
>
> The problem is I can't use the sendmail function, because it requires
> saving the new workbook to the disk (as far as I know) and because of
> profile space limitations this is not workable for me).
>
> The other problem, when the workbook is created a button is created to
> allow the user to close the workbook and return to the main workbook.
> That works fine except when the email recipient opens the file.
>
> there is a prompt about broken links (which is obviously because of
> the button).
> I understand that it is not possible to avoid that prompt with excel
> 2003
>
> So I decided to get rid of the button and just wait for the new
> workbook to be closed before returning to the main workbook and
> continuing with the macro
> Another problem then, excel of course prompts to save the new
> workbook.
>
>
> Can I eliminate the Broken/Update link prompt when opening the
> workbook?
>
> OR
>
> How can I close the workbook without prompt??
> (i am not sre if I can inject code from a macro into the new workbook
> to detect close event??)
>
>
>
>
>
>



 
Reply With Quote
 
HammerJoe@gmail.com
Guest
Posts: n/a
 
      29th Jun 2008
This is brilliant, thanks Doug.
 
Reply With Quote
 
Doug Glancy
Guest
Posts: n/a
 
      29th Jun 2008
I'm glad you like it! I've just recently really understood how powerful
classes are in this regard.

Doug

<(E-Mail Removed)> wrote in message
news:deda9891-0482-4659-8bc0-(E-Mail Removed)...
> This is brilliant, thanks Doug.



 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Avoid Prompts on Workbook open? J.W. Aldridge Microsoft Excel Programming 1 29th May 2008 02:39 AM
Open New Workbook / Save and Close Current Workbook Joe K. Microsoft Excel Programming 1 7th Dec 2007 08:04 PM
Re: Open workbook on close Mike Microsoft Excel Programming 0 8th Jan 2007 10:24 PM
Excel VBA Close Workbook and Open Existing Workbook rjm65 Microsoft Excel Programming 1 22nd Dec 2004 06:56 AM
Excel-Can't close 1 open Workbook without closing other open Workb =?Utf-8?B?ZnJhbWluZ2hhbQ==?= Microsoft Excel Misc 1 18th Oct 2004 08:59 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 06:33 PM.