Go Back   Trackpads Community > General Discussions > Computer and Technology > Microsoft Applications

Microsoft Applications Discussions about Windows and other MS Products such as Office

Reply
 
LinkBack Thread Tools
Old 01-17-2005, 16:00   #1 (permalink)
CarlosAntenna
Civilians

 
Default VBA Help Needed

I created a workbook and saved it as a template to be used repeatedly. It
uses a query to select and extract data from an external database. The
query refreshes automatically when the workbook is opened. I recorded a
macro to save this subset of data as a database file (dBase4) and set it to
save before the workbook is closed. It works OK, but I would like make it
even better. How can I supress the two questions that pop up?

"Do you want to replace the existing file?" (yes).
"Do you want to save changes to ups.dbf?" (no).

Here is the macro:

Private Sub Workbook_BeforeClose(Cancel As Boolean)
ChDir "S:\"
ActiveWorkbook.SaveAs Filename:="S:\ups.dbf", FileFormat:=xlDBF4, _
CreateBackup:=False
End Sub

--
Carlos


 
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Trackpads Information
Click to Visit
Old 01-17-2005, 19:00   #2 (permalink)
Paulw2k
Civilians

 
Default Re: VBA Help Needed

Private Sub Workbook_BeforeClose(Cancel As Boolean)
ChDir "S:\"

Application.DisplayAlerts = False

ActiveWorkbook.SaveAs Filename:="S:\ups.dbf", FileFormat:=xlDBF4, _
CreateBackup:=False
Application.DisplayAlerts = True

End Sub



From VBA Help File
DisplayAlerts Property
True if Microsoft Excel displays certain alerts and messages while a macro
is running. Read/write Boolean.
Remarks
The default value is True. Set this property to False if you don't want to
be disturbed by prompts and alert messages while a macro is running; any
time a message requires a response, Microsoft Excel chooses the default
response.

If you set this property to False, Micorosoft Excel sets this property to
True when the code is finished, unless you are running cross process code.

When using the SaveAs method for workbooks to overwrite an existing file,
the 'Overwrite' alert has a default of 'No', while the 'Yes' response is
selected by Excel when the DisplayAlerts property is set equal to True.







"CarlosAntenna" <nunayo@binnez.com> wrote in message
news:%23SFIKmM$EHA.3592@TK2MSFTNGP09.phx.gbl...
>I created a workbook and saved it as a template to be used repeatedly. It
> uses a query to select and extract data from an external database. The
> query refreshes automatically when the workbook is opened. I recorded a
> macro to save this subset of data as a database file (dBase4) and set it
> to
> save before the workbook is closed. It works OK, but I would like make it
> even better. How can I supress the two questions that pop up?
>
> "Do you want to replace the existing file?" (yes).
> "Do you want to save changes to ups.dbf?" (no).
>
> Here is the macro:
>
> Private Sub Workbook_BeforeClose(Cancel As Boolean)
> ChDir "S:\"
> ActiveWorkbook.SaveAs Filename:="S:\ups.dbf", FileFormat:=xlDBF4, _
> CreateBackup:=False
> End Sub
>
> --
> Carlos
>
>



 
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Old 01-17-2005, 20:00   #3 (permalink)
CarlosAntenna
Civilians

 
Default Re: VBA Help Needed

Thanks, Paul,

That takes care of the first one (overwrite). I still get the second one.
I think that one is triggered by closing the worksheet rather than from
within the macro. Can the macro also close the workbook while
DisplayAlerts=False?

--
Carlos

"Paulw2k" <paulw2k@hotmail.com> wrote in message
news:cshdk1$c1f$1@news6.svr.pol.co.uk...
> Private Sub Workbook_BeforeClose(Cancel As Boolean)
> ChDir "S:\"
>
> Application.DisplayAlerts = False
>
> ActiveWorkbook.SaveAs Filename:="S:\ups.dbf", FileFormat:=xlDBF4, _
> CreateBackup:=False
> Application.DisplayAlerts = True
>
> End Sub
>
>
>
> From VBA Help File
> DisplayAlerts Property
> True if Microsoft Excel displays certain alerts and messages while a macro
> is running. Read/write Boolean.
> Remarks
> The default value is True. Set this property to False if you don't want to
> be disturbed by prompts and alert messages while a macro is running; any
> time a message requires a response, Microsoft Excel chooses the default
> response.
>
> If you set this property to False, Micorosoft Excel sets this property to
> True when the code is finished, unless you are running cross process code.
>
> When using the SaveAs method for workbooks to overwrite an existing file,
> the 'Overwrite' alert has a default of 'No', while the 'Yes' response is
> selected by Excel when the DisplayAlerts property is set equal to True.
>
>
>
>
>
>
>
> "CarlosAntenna" <nunayo@binnez.com> wrote in message
> news:%23SFIKmM$EHA.3592@TK2MSFTNGP09.phx.gbl...
> >I created a workbook and saved it as a template to be used repeatedly.

It
> > uses a query to select and extract data from an external database. The
> > query refreshes automatically when the workbook is opened. I recorded a
> > macro to save this subset of data as a database file (dBase4) and set it
> > to
> > save before the workbook is closed. It works OK, but I would like make

it
> > even better. How can I supress the two questions that pop up?
> >
> > "Do you want to replace the existing file?" (yes).
> > "Do you want to save changes to ups.dbf?" (no).
> >
> > Here is the macro:
> >
> > Private Sub Workbook_BeforeClose(Cancel As Boolean)
> > ChDir "S:\"
> > ActiveWorkbook.SaveAs Filename:="S:\ups.dbf", FileFormat:=xlDBF4, _
> > CreateBackup:=False
> > End Sub
> >
> > --
> > Carlos
> >
> >

>
>



 
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Old 01-17-2005, 20:00   #4 (permalink)
Dave Peterson
Civilians

 
Default Re: VBA Help Needed

This would kind of scare me--if I made changes that I really wanted to save and
then suppressed that prompt.

I think I'd move the save as .dbf to an "on demand" macro--not have it called
from _beforeclose.

But this did work ok for me:

Option Explicit
Private Sub Workbook_BeforeClose(Cancel As Boolean)
Application.DisplayAlerts = False
ActiveWorkbook.SaveAs Filename:="S:\ups.dbf", FileFormat:=xlDBF4, _
CreateBackup:=False
Application.DisplayAlerts = True
Me.Saved = True
End Sub

(There's no reason to change to a different drive if you specify the path in the
..SaveAs line.)

CarlosAntenna wrote:
>
> Thanks, Paul,
>
> That takes care of the first one (overwrite). I still get the second one.
> I think that one is triggered by closing the worksheet rather than from
> within the macro. Can the macro also close the workbook while
> DisplayAlerts=False?
>
> --
> Carlos
>
> "Paulw2k" <paulw2k@hotmail.com> wrote in message
> news:cshdk1$c1f$1@news6.svr.pol.co.uk...
> > Private Sub Workbook_BeforeClose(Cancel As Boolean)
> > ChDir "S:\"
> >
> > Application.DisplayAlerts = False
> >
> > ActiveWorkbook.SaveAs Filename:="S:\ups.dbf", FileFormat:=xlDBF4, _
> > CreateBackup:=False
> > Application.DisplayAlerts = True
> >
> > End Sub
> >
> >
> >
> > From VBA Help File
> > DisplayAlerts Property
> > True if Microsoft Excel displays certain alerts and messages while a macro
> > is running. Read/write Boolean.
> > Remarks
> > The default value is True. Set this property to False if you don't want to
> > be disturbed by prompts and alert messages while a macro is running; any
> > time a message requires a response, Microsoft Excel chooses the default
> > response.
> >
> > If you set this property to False, Micorosoft Excel sets this property to
> > True when the code is finished, unless you are running cross process code.
> >
> > When using the SaveAs method for workbooks to overwrite an existing file,
> > the 'Overwrite' alert has a default of 'No', while the 'Yes' response is
> > selected by Excel when the DisplayAlerts property is set equal to True.
> >
> >
> >
> >
> >
> >
> >
> > "CarlosAntenna" <nunayo@binnez.com> wrote in message
> > news:%23SFIKmM$EHA.3592@TK2MSFTNGP09.phx.gbl...
> > >I created a workbook and saved it as a template to be used repeatedly.

> It
> > > uses a query to select and extract data from an external database. The
> > > query refreshes automatically when the workbook is opened. I recorded a
> > > macro to save this subset of data as a database file (dBase4) and set it
> > > to
> > > save before the workbook is closed. It works OK, but I would like make

> it
> > > even better. How can I supress the two questions that pop up?
> > >
> > > "Do you want to replace the existing file?" (yes).
> > > "Do you want to save changes to ups.dbf?" (no).
> > >
> > > Here is the macro:
> > >
> > > Private Sub Workbook_BeforeClose(Cancel As Boolean)
> > > ChDir "S:\"
> > > ActiveWorkbook.SaveAs Filename:="S:\ups.dbf", FileFormat:=xlDBF4, _
> > > CreateBackup:=False
> > > End Sub
> > >
> > > --
> > > Carlos
> > >
> > >

> >
> >


--

Dave Peterson
 
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Old 01-17-2005, 21:00   #5 (permalink)
CarlosAntenna
Civilians

 
Default Re: VBA Help Needed

Thanks Dave,

It works great. Not scary because the data is coming from a query that only
takes a second or two to run. I can always run it again if something goes
wrong.

I thought the ChDir was redundant, but I didn't code this macro. I recorded
it. Thanks for confirming that.

--
Carlos
"Dave Peterson" <ec35720@netscapeXSPAM.com> wrote in message
news:41EC4AF5.3ADD5F3D@netscapeXSPAM.com...
> This would kind of scare me--if I made changes that I really wanted to
> save and
> then suppressed that prompt.
>
> I think I'd move the save as .dbf to an "on demand" macro--not have it
> called
> from _beforeclose.
>
> But this did work ok for me:
>
> Option Explicit
> Private Sub Workbook_BeforeClose(Cancel As Boolean)
> Application.DisplayAlerts = False
> ActiveWorkbook.SaveAs Filename:="S:\ups.dbf", FileFormat:=xlDBF4, _
> CreateBackup:=False
> Application.DisplayAlerts = True
> Me.Saved = True
> End Sub
>
> (There's no reason to change to a different drive if you specify the path
> in the
> .SaveAs line.)
>
> CarlosAntenna wrote:
>>
>> Thanks, Paul,
>>
>> That takes care of the first one (overwrite). I still get the second
>> one.
>> I think that one is triggered by closing the worksheet rather than from
>> within the macro. Can the macro also close the workbook while
>> DisplayAlerts=False?
>>
>> --
>> Carlos
>>
>> "Paulw2k" <paulw2k@hotmail.com> wrote in message
>> news:cshdk1$c1f$1@news6.svr.pol.co.uk...
>> > Private Sub Workbook_BeforeClose(Cancel As Boolean)
>> > ChDir "S:\"
>> >
>> > Application.DisplayAlerts = False
>> >
>> > ActiveWorkbook.SaveAs Filename:="S:\ups.dbf", FileFormat:=xlDBF4, _
>> > CreateBackup:=False
>> > Application.DisplayAlerts = True
>> >
>> > End Sub
>> >
>> >
>> >
>> > From VBA Help File
>> > DisplayAlerts Property
>> > True if Microsoft Excel displays certain alerts and messages while a
>> > macro
>> > is running. Read/write Boolean.
>> > Remarks
>> > The default value is True. Set this property to False if you don't want
>> > to
>> > be disturbed by prompts and alert messages while a macro is running;
>> > any
>> > time a message requires a response, Microsoft Excel chooses the default
>> > response.
>> >
>> > If you set this property to False, Micorosoft Excel sets this property
>> > to
>> > True when the code is finished, unless you are running cross process
>> > code.
>> >
>> > When using the SaveAs method for workbooks to overwrite an existing
>> > file,
>> > the 'Overwrite' alert has a default of 'No', while the 'Yes' response
>> > is
>> > selected by Excel when the DisplayAlerts property is set equal to True.
>> >
>> >
>> >
>> >
>> >
>> >
>> >
>> > "CarlosAntenna" <nunayo@binnez.com> wrote in message
>> > news:%23SFIKmM$EHA.3592@TK2MSFTNGP09.phx.gbl...
>> > >I created a workbook and saved it as a template to be used repeatedly.

>> It
>> > > uses a query to select and extract data from an external database.
>> > > The
>> > > query refreshes automatically when the workbook is opened. I
>> > > recorded a
>> > > macro to save this subset of data as a database file (dBase4) and set
>> > > it
>> > > to
>> > > save before the workbook is closed. It works OK, but I would like
>> > > make

>> it
>> > > even better. How can I supress the two questions that pop up?
>> > >
>> > > "Do you want to replace the existing file?" (yes).
>> > > "Do you want to save changes to ups.dbf?" (no).
>> > >
>> > > Here is the macro:
>> > >
>> > > Private Sub Workbook_BeforeClose(Cancel As Boolean)
>> > > ChDir "S:\"
>> > > ActiveWorkbook.SaveAs Filename:="S:\ups.dbf", FileFormat:=xlDBF4,
>> > > _
>> > > CreateBackup:=False
>> > > End Sub
>> > >
>> > > --
>> > > Carlos
>> > >
>> > >
>> >
>> >

>
> --
>
> Dave Peterson



 
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply

Bookmarks

Thread Tools

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 On

Similar Threads
Thread Thread Starter Forum Replies Last Post
help needed please Pete Web Design 0 10-26-2005 14:37
Help Needed! Panos Popadopalous Automotive 20 05-14-2005 12:00
Re: RBS changes needed Dale Howard [MVP] Microsoft Applications 1 02-12-2005 00:00
Help needed Vanessa Kehoe Microsoft Applications 6 12-08-2004 19:00
Help needed Rommel Army 3 02-24-2004 18:11


Community Information
Options
Quick Options
Trackpads Non-Commercial Ad
Copyright Information Click to Visit
Time
Server Time
All times are GMT -4. The time now is 13:13.
Copyright
Copyright Information
The header is based off of work by Vipixel.com and modified by this site. Trackpads and the Trackpads Logo are both Registered Trademarks of Jason Edwards and cannot be used without prior written permission.  The only exception is as a link back to this site. Trackpads is a private website run by a small legion of volunteers, 3 dogs, 12.5 cats and an army of small, super smart, bio-engineered mice with pointy hats and tutu's. Search Engine Friendly URLs by vBSEO 3.2.0 RC7
Archive Links
Archive Links
Page generated in 0.74871 seconds with 19 queries