Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 161
Default Quick file overwrite script

Is there a quick VBA script that will go into each file in a directory
and overwrite it with at least 100K of random text or data?
Ive been doing it manually with copy and paste, so I know there's
gotta be an easier way, ughh, hahaha.



  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,514
Default Quick file overwrite script

Is there a quick VBA script that will go into each file in a
directory
and overwrite it with at least 100K of random text or data?
Ive been doing it manually with copy and paste, so I know there's
gotta be an easier way, ughh, hahaha.


What kind of files? Assuming plain text...

Absolutely no problem using VB[A]'s built-in file I/O features and a
Dir drill procedure! *However*, I will not post such code due to its
very high potential to be used for terrorism on other unsuspecting
computers!

You can look into these VB[A} functions/methods for more info...

Open()
FreeFile()
Put
Get
Close()

fixed length string
buffer size

...where the above will replace existing files with a new file of the
same filename.

For Excel files you should look at using ADODB so you won't need to
have each file opened in Excel.

--
Garry

Free usenet access at http://www.eternal-september.org
Classic VB Users Regroup!
comp.lang.basic.visual.misc
microsoft.public.vb.general.discussion


  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,514
Default Quick file overwrite script

Here's my standard (reusable) procedure for writing plain text files...


Sub WriteTextFile(TextOut$, Filename$, _
Optional AppendMode As Boolean = False)
' Reusable procedure that Writes/Overwrites or Appends
' large amounts of data to a Text file in one single step.
' **Does not create a blank line at the end of the file**
Dim iNum%
On Error GoTo ErrHandler
iNum = FreeFile()
If AppendMode Then
Open Filename For Append As #iNum: Print #iNum, vbCrLf & TextOut;
Else
Open Filename For Output As #iNum: Print #iNum, TextOut;
End If

ErrHandler:
Close #iNum: If Err Then Err.Raise Err.Number, , Err.Description
End Sub 'WriteTextFile

--
Garry

Free usenet access at http://www.eternal-september.org
Classic VB Users Regroup!
comp.lang.basic.visual.misc
microsoft.public.vb.general.discussion


  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 538
Default Quick file overwrite script

GS wrote:

Is there a quick VBA script that will go into each file in a
directory
and overwrite it with at least 100K of random text or data?
Ive been doing it manually with copy and paste, so I know there's
gotta be an easier way, ughh, hahaha.


What kind of files? Assuming plain text...

Absolutely no problem using VB[A]'s built-in file I/O features and a
Dir drill procedure! *However*, I will not post such code due to its
very high potential to be used for terrorism on other unsuspecting
computers!


The posting of such code here, or lack of same, isn't going to affect the
ability of a person to find such code, or a program to do the same. Even
Microsoft offers programs to do what the OP is asking for.

--
I'll be watchin', waitin', fallin', shakin'.
  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 538
Default Quick file overwrite script

Robert Crandal wrote:

Is there a quick VBA script that will go into each file in a directory
and overwrite it with at least 100K of random text or data?
Ive been doing it manually with copy and paste, so I know there's
gotta be an easier way, ughh, hahaha.


Why? What are you trying to accomplish? Secure deletion? Or something else?

--
Heaven knows there's nothing worse than a cocky beggar.


  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,514
Default Quick file overwrite script

GS wrote:

Is there a quick VBA script that will go into each file in a
directory
and overwrite it with at least 100K of random text or data?
Ive been doing it manually with copy and paste, so I know there's
gotta be an easier way, ughh, hahaha.


What kind of files? Assuming plain text...

Absolutely no problem using VB[A]'s built-in file I/O features and a
Dir drill procedure! *However*, I will not post such code due to its
very high potential to be used for terrorism on other unsuspecting
computers!


The posting of such code here, or lack of same, isn't going to affect
the ability of a person to find such code, or a program to do the
same. Even Microsoft offers programs to do what the OP is asking
for.


Be that it may.., I choose to *NOT* propagate such code!<g

--
Garry

Free usenet access at http://www.eternal-september.org
Classic VB Users Regroup!
comp.lang.basic.visual.misc
microsoft.public.vb.general.discussion


  #7   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,514
Default Quick file overwrite script

Is there a quick VBA script that will go into each file in a
directory
and overwrite it with at least 100K of random text or data?
Ive been doing it manually with copy and paste, so I know there's
gotta be an easier way, ughh, hahaha.


Here's some generic procs that drill for files in a specified folder
and any subfolders...

--
Garry

Free usenet access at http://www.eternal-september.org
Classic VB Users Regroup!
comp.lang.basic.visual.misc
microsoft.public.vb.general.discussion


  #8   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,514
Default Quick file overwrite script

Here's some generic procs that drill for files in a specified folder
and any subfolders...


Sub DirDrillFldrs()
' Lists all files in a folder.
' Calls out to list all files in subfolders.

Dim vFldr, vFile, sTopFldr$

On Error GoTo Cleanup
sTopFldr = GetDirectory '//prompt user for parent folder
If sTopFldr = "" Then Exit Sub '//user cancels

Set vFldr =
CreateObject("Scripting.FileSystemObject").GetFold er(sTopFldr)
Debug.Print vFldr.Path
For Each vFile In vFldr.Files: Debug.Print vbTab & vFile.name: Next

DirDrillSubFldrs vFldr '//optionally drill each subfolder

Cleanup:
Set vFldr = Nothing
End Sub

Sub DirDrillSubFldrs(Folder)
' Lists all files in 'Folder'
' Recursively lists all subfolders/files

Dim vSubFldr, vFile, vFiles

On Error GoTo Cleanup
For Each vSubFldr In Folder.SubFolders
Debug.Print vSubFldr.Path

Set vFiles =
CreateObject("Scripting.FileSystemObject").GetFold er(vSubFldr.Path).Files

For Each vFile In vFiles: Debug.Print vbTab & vFile.name: Next
DirDrillSubFldrs vSubFldr
Next

Cleanup:
Set vFiles = Nothing
End Sub

Function GetDirectory$(Optional OpenAt, Optional Msg$)
' Returns the path of a user selected folder
' Note: By default, dialog opens at 'Desktop'
' Args:
' OpenAt Optional: Path to the dialog's top level folder
' Msg Optional: The dialog's title

If Msg = "" Then Msg = "Please choose a folder"
On Error Resume Next '//if user cancels
GetDirectory = CreateObject("Shell.Application").BrowseForFolder( 0,
Msg, &H40 Or &H10, OpenAt).Self.Path
End Function 'GetDirectory()

--
Garry

Free usenet access at http://www.eternal-september.org
Classic VB Users Regroup!
comp.lang.basic.visual.misc
microsoft.public.vb.general.discussion


Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

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
Excel File Overwrite GradAsh10 Excel Discussion (Misc queries) 1 January 18th 10 04:13 PM
how to save a file and overwrite existing file Daniel M Excel Programming 1 January 18th 08 07:45 PM
Prevent PivotTable Overwrite Warning and Disallow Overwrite jonahviakeyboard Excel Programming 0 November 27th 07 05:08 PM
Overwrite saved workbook in VB Script Martin X. Excel Programming 2 August 13th 07 03:46 PM
Say 'YES' to overwrite file Mike G. Excel Programming 6 June 1st 04 06:58 PM


All times are GMT +1. The time now is 04:05 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"