How do I corrupt an Excel File?
A friend needs a favor from me...
I need to "corrupt" an excel file so it wont open
I cant just delete the file becuase thats too obvious
How can I make the excle file still there but wont load.
I tried opening it in wordpad...and deleting the 1st 20 rows...
and that sort of works but it still kind of loads.
I know this sounds fishy...but many of you know me and you know Im doing anything funny (like creating a virus! :eek: )
any Ideas?
-Static
Re: How do I corrupt an Excel File?
Hiya,
I suppose you could try opening the file for read/write access, read in a byte at a time, divide by two, write out, next byte, etc, etc...
Alternatively add a script to the "Workbooks_Open" method to show a messagebox saying "This file is corrupt" and then close it. That may work?
DJ
Re: How do I corrupt an Excel File?
Option 2 is no good...
but the read write is a good idea...
Ive never played with Bytes..not sure how I would do it.
Open FileName for Binary as #1 ?
etc...
code sample please! Thanks!
1 Attachment(s)
Re: How do I corrupt an Excel File?
Attached is some file load and save functions.
Use these to get a byte array of the file...ie
If the file was say: 1234567890
Then the byte array will have 10 entries.
Create a 2nd byte array of the same length, then copy
12345 to the LAST 5 bytes, and
67890 to the 1st
then save the byte array to another file.
The file should look like 6789012345
I am sure this will bust the file :D
Woka
Re: How do I corrupt an Excel File?
ok..will check it out at home tonight... (No VB here at work...just Access :rolleyes: )
Re: How do I corrupt an Excel File?
Hi,
An easy easy way to break this is to take any file (a Zip for example) and copy it to the file making sure that the file extension becomes .XLS. When Excel tries to open the file it will be reading and looking for certain file structures/signatures/etc... so it will fail. A nice easy method....
HTH,
DJ
Re: How do I corrupt an Excel File?
Using the code I attached in my above post, you then need:
Code:
Dim lngIndex As Long
Dim bytData() As Byte
Dim bytNew() As Byte
Dim lngUBound As Long
Dim lngMid As Long
bytData = GetFile("C:\Woof.xls")
lngUBound = UBound(bytData)
lngMid = lngUBound / 2
ReDim bytNew(lngUBound)
For lngIndex = 0 To lngMid
bytNew(lngIndex) = bytData(lngUBound - lngMid + lngIndex)
Next lngIndex
For lngIndex = lngMid + 1 To lngUBound
bytNew(lngIndex - lngMid - 1) = bytData(lngIndex)
Next lngIndex
SaveFile "C:\new.xls", bytNew
When I try to open the xls file it says it doesn't recognise the form.
This seems to work, but a better way would be to take the byte array:
1234567890
And then split in half
12345
67890
and then interweave the bytes
6172839405
That would bust any file :D
But you cans till get the file back by doing the reverse.
Woka
Re: How do I corrupt an Excel File?
A nice way would be to change the file in such a way so you reverse the change if really needed.
You can use the NOT operator to reverse the bytes in the file, and if you reverse again, then the file will be readable again, same way you can use XOR.
Here's what I mean:
VB Code:
Option Explicit
Private Sub ReverseByteNumbers(ByVal FileName As String)
Dim K As Long, byteArr() As Byte, FL As Integer
FL = FreeFile
Open FileName For Binary Access Read Write Lock Read Write As FL
ReDim byteArr(LOF(FL) - 1)
Get FL, , byteArr
For K = 0 To UBound(byteArr)
byteArr(K) = Not byteArr(K)
Next K
Put FL, 1, byteArr
Close FL
End Sub
Private Sub XORFile(ByVal FileName As String, XORNumber As Byte)
Dim K As Long, byteArr() As Byte, FL As Integer
FL = FreeFile
Open FileName For Binary Access Read Write Lock Read Write As FL
ReDim byteArr(LOF(FL) - 1)
Get FL, , byteArr
For K = 0 To UBound(byteArr)
byteArr(K) = byteArr(K) Xor XORNumber
Next K
Put FL, 1, byteArr
Close FL
End Sub
Private Sub Form_Load()
ReverseByteNumbers "C:\TestFile.xls"
XORFile "C:\TestFile 2.xls", 200
End Sub
I did not actually try this code...
If you run the same function on the "damaged" file, it will fix it back...
Re: How do I corrupt an Excel File?
the XOR code is perfect!
"Can not Access 'TestFile2.xls'"
wont even load it!
Thanks Much!!
EDIT - Oops.. lol..I can load it...I did 'Close FL' :rolleyes:
but it works...both functions scramble it
Thanks!
1 Attachment(s)
Re: How do I corrupt an Excel File?
Hi,
You can try using this manual process to recover your workbook:
1- Click File > Open.
2- Click the location and folder that contains the corrupted workbook.
3- In the Open dialog box, select the corrupted workbook.
4- Click the arrow next to the Open button, and then click Open and Repair.
Attachment 160517
5- To recover as much of the workbook data as possible, pick Repair.
Re: How do I corrupt an Excel File?
Quote:
Originally Posted by
Static
A friend needs a favor from me...
I need to "corrupt" an excel file so it wont open
I cant just delete the file becuase thats too obvious
How can I make the excle file still there but wont load.
I tried opening it in wordpad...and deleting the 1st 20 rows...
and that sort of works but it still kind of loads.
I know this sounds fishy...but many of you know me and you know Im doing anything funny (like creating a virus! :eek: )
any Ideas?
-Static
Change an image file's extension to .xlsx. That should do it :eek:
Re: How do I corrupt an Excel File?
Quote:
Originally Posted by
Static
A friend needs a favor from me...
I need to "corrupt" an excel file so it wont open
I cant just delete the file becuase thats too obvious
How can I make the excle file still there but wont load.
I tried opening it in wordpad...and deleting the 1st 20 rows...
and that sort of works but it still kind of loads.
I know this sounds fishy...but many of you know me and you know Im doing anything funny (like creating a virus! :eek: )
any Ideas?
-Static
Change an image file's extension to .xlsx. That should do it :eek:
Re: How do I corrupt an Excel File?
This thread is 13 years old...
Re: How do I corrupt an Excel File?
eric_hayes, OP 13-years ago wanted to damage file.
However, interesting info from you.