Home |
Search |
Today's Posts |
|
#1
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
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
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
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
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
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
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
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
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
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 |
#6
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
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. |
#7
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
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
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
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 |
Display Modes | |
|
|
![]() |
||||
Thread | Forum | |||
Excel File Overwrite | Excel Discussion (Misc queries) | |||
how to save a file and overwrite existing file | Excel Programming | |||
Prevent PivotTable Overwrite Warning and Disallow Overwrite | Excel Programming | |||
Overwrite saved workbook in VB Script | Excel Programming | |||
Say 'YES' to overwrite file | Excel Programming |