For Programmers: Free Programming Magazines  


Home > Archive > Visual Basic Syntax > January 2006 > Overwriting a file in VB









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author Overwriting a file in VB
Crash

2006-01-23, 7:08 pm

I'm creating a macro that saves some files each w. I wanted to save the
files over top of the files from last w. Each time I run the macro it
asks me to overwrite the files and I would like it to just do it without
asking.

Ideas?
Karl E. Peterson

2006-01-23, 7:08 pm

Crash wrote:
> I'm creating a macro that saves some files each w. I wanted to
> save the files over top of the files from last w. Each time I run
> the macro it asks me to overwrite the files and I would like it to
> just do it without asking.


Sounds like you're using VBA within an Office app? What/where?

True VB file i/o never prompts you for anything.
--
Be the 10,000th Signer!
http://classicvb.org


Crash

2006-01-23, 7:08 pm

Yeah, I'm actually using VB script inside an Excel document.

"Karl E. Peterson" wrote:

> Crash wrote:
>
> Sounds like you're using VBA within an Office app? What/where?
>
> True VB file i/o never prompts you for anything.
> --
> Be the 10,000th Signer!
> http://classicvb.org
>
>
>

Karl E. Peterson

2006-01-23, 7:08 pm

Crash wrote:
>
> Yeah, I'm actually using VB script inside an Excel document.


VBA, actually. VBS is another beast entirely. (These are *not* petty
distinctions, either.)

In Excel, you can set the Application.DisplayAlerts property to False, do
the dirty deed, then set it back to True.
--
Be the 10,000th Signer!
http://classicvb.org


Douglas J. Steele

2006-01-29, 7:57 am

"Karl E. Peterson" <karl@mvps.org> wrote in message
news:Ov$EMuGIGHA.2680@TK2MSFTNGP09.phx.gbl...
> Crash wrote:
>
> VBA, actually. VBS is another beast entirely. (These are *not* petty
> distinctions, either.)
>
> In Excel, you can set the Application.DisplayAlerts property to False, do
> the dirty deed, then set it back to True.


Or you can issue a Kill statement to delete the file, and ignore any error
that might arise if the file doesn't already exist.

On Error Resume Next
Kill strFile

If that offends you <g>, you can check whether the file exists using:

If Len(Dir(strFile)) > 0 Then
Kill strFile
End If

--
Doug Steele, Microsoft Access MVP
http://I.Am/DougSteele
(no private e-mails, please)



Karl E. Peterson

2006-01-30, 7:06 pm

Douglas J. Steele wrote:
> "Karl E. Peterson" <karl@mvps.org> wrote in message
> news:Ov$EMuGIGHA.2680@TK2MSFTNGP09.phx.gbl...
>
> Or you can issue a Kill statement to delete the file, and ignore any
> error that might arise if the file doesn't already exist.
>
> On Error Resume Next
> Kill strFile


Heh, far cleaner, yeah. <g> Doesn't offer the option of reverting to asking
the user, but then, well, what do users know anyway, huh? <bg>

> If that offends you <g>, you can check whether the file exists using:
>
> If Len(Dir(strFile)) > 0 Then
> Kill strFile
> End If


Nah! That actually offends me more! <g>
--
Working without a .NET?
http://classicvb.org/


Larry Serflaten

2006-01-30, 7:06 pm


"Karl E. Peterson" <karl@mvps.org> wrote

>
> Nah! That actually offends me more! <g>



MsgBox "OK to delete this file?", vbOKOnly
Kill strFile


Karl E. Peterson

2006-01-30, 7:06 pm

Larry Serflaten wrote:
> "Karl E. Peterson" <karl@mvps.org> wrote
>
>
> MsgBox "OK to delete this file?", vbOKOnly
> Kill strFile


My problem, old story, was using Dir() to test for FileEists.
--
Working without a .NET?
http://classicvb.org/


Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2008 codecomments.com