Walker News

How To Extract SWF Flash From Excel or Word

Besides watching Flash videos (FLV files), you should have seen or played some Flash animation game as well (SWF files, a.k.a. Shockwave flash).
And most of the time, you received SWF Flash animation in Microsoft Office document. Very likely, the SWF animation file is embedded in Office Excel.
The reason of embedding SWF animation file in Office document is probably that majority of users is running on Windows / MS Office, and MS Office can serve as a container to run or play the SWF file.

(If you received an un-embedded SWF file, you might able to open and play the SWF animation in web browser that installed with Shockwave Flash add-on)

While the SWF flash appears as an embedded file in Office Excel or Word, you might want to extract or retrieve the embedded SWF flash for your blog.

However, there is no intrinsic or built-in function to extract / retrieve embedded SWF Flash animation from Microsoft Office document files. This is definitely true, that you won’t able to find this wanted feature in Office 2007 as well!

So, how could you do that in case you’re really wanted to do so? OK, here we go:

How to extract SWF Flash animation from Office Excel?

A simple VBA program (a.k.a Visual Basic for Applications) can extract the embedded SWF Flash animation file in less than a minute or so.

The VBA / guide has been tested in Office 2003 Professional, and it should be working perfectly in any Office versions / editions too (e.g. the latest Office 2007), provided the Office system has installed the VBA components.
  1. Open a new Microsoft Excel document,
     
  2. Click the Tools menu, Marco, Visual Basic Editor. You can also press the ALT+ F11 hotkey to bring up the VBA editor,
     
  3. While in MS Visual Basic editor, click the View Code icon on the upper-left panel,
    VBA program to extract or retrieve embedded SWF Flash animation in Excel.
     
  4. Copy the VBA program source code at below here and paste it onto the VBA source code editor,
     
  5. Press F5 to execute the VBA source code,
     
  6. An Open File dialog box prompts you to select the Office Excel document that embed the SWF Flash animation file,
     
  7. A message box appears shortly after the Excel file is selected, with a message that says where the extracted SWF Flash animation file is saved in local hard disk!

The extracted SWF Flash animation file ended with SWF file extension, and it can be open/play in a web browser with Shockwave Flash addon (e.g. Flash9e.ocx in IE7).

The VBA source code used to extract or retrieve SWF Flash animation files that embedded in Microsoft Office Excel or Word:
Sub ExtractFlash()

Dim tmpFileName As String
Dim FileNumber As Integer
Dim myFileId As Long
Dim MyFileLen As Long
Dim myIndex As Long
Dim swfFileLen As Long
Dim i As Long
Dim swfArr() As Byte
Dim myArr() As Byte

tmpFileName = Application.GetOpenFilename("MS Office File (*.doc;*.xls), *.doc;*.xls", , "Open MS Office file")

If tmpFileName = "False" Then Exit Sub

myFileId = FreeFile

Open tmpFileName For Binary As #myFileId

MyFileLen = LOF(myFileId)

ReDim myArr(MyFileLen - 1)

Get myFileId, , myArr()

Close myFileId

Application.ScreenUpdating = False

i = 0

Do While i < MyFileLen

   If myArr(i) = &H46 Then

      If myArr(i + 1) = &H57 And myArr(i + 2) = &H53 Then

         swfFileLen = CLng(&H1000000) * myArr(i + 7) + CLng(&H10000) * myArr(i + 6) + CLng(&H100) * myArr(i + 5) + myArr(i + 4)

         ReDim swfArr(swfFileLen - 1)

         For myIndex = 0 To swfFileLen - 1
            swfArr(myIndex) = myArr(i + myIndex)
            Next myIndex
         Exit Do

      Else
            i = i + 3
      End If

   Else
        i = i + 1
   End If

Loop

myFileId = FreeFile

tmpFileName = Left(tmpFileName, Len(tmpFileName) - 4) & ".swf"

Open tmpFileName For Binary As #myFileId

Put #myFileId, , swfArr

Close myFileId

MsgBox "Save the extracted SWF Flash as [ " & tmpFileName & " ]"

End Sub

Credit of the VBA code given to a Chinese blogger called Emily.


Custom Search

  1. King Fisher May 29th, 2008 7:10 PM

    Bravo… excellent.. :)

  2. Chikz June 20th, 2008 5:38 PM

    Excellent!!!!!!!!!!!!!!!!

  3. Bypass Exchange Server Attachment Filtering System – Walker News June 24th, 2008 6:49 PM

    [...] inserting the compressed executable program file as an embedded object in Microsoft Excel / Word, the Exchange server attachment filtering system automatically “allow” the email [...]

  4. akm August 1st, 2008 10:19 PM

    Very fine work..
    Great computer genius.

  5. raghu August 9th, 2008 10:00 PM

    hi,
    thanks very much.
    can you please explain the logic also. don’t really understand the binary part & other parts in it. why is it required? can you please explain it. PLEASE…
    thanks.
    regards
    Raghu

  6. Wally September 1st, 2008 2:07 AM

    Thanks a lot for this works great

  7. SWF-Extractor: A Hungarian Freeware To Extract SWF From Microsoft Excel And Word Document – Walker News September 12th, 2008 12:36 AM

    [...] time ago, I wrote a post about how to extract SWF (Shockwave Flash) that embedded in Microsoft Excel or Word document. That’s not about [...]

  8. pax September 15th, 2008 9:39 PM

    excelent ……………….
    Thanks a lot for this works great

  9. Bamoi November 3rd, 2008 12:39 AM

    U are a genius!!! thx man

  10. Alonso November 27th, 2008 11:40 PM

    Great men, so helpfull

    Alonso From Ecuador

  11. Thiago December 6th, 2008 1:04 AM

    Fantastic dude!

    excellent code! this code was made in C++?

    Thanks

    Thiago from Brazil

  12. KumC January 10th, 2009 6:39 AM

    ThX….A…….LooooooooT
    DuDe…………………………VeRy…..NiCe
    ” KumCLilli “

  13. Suz February 10th, 2009 2:21 PM

    Superb job…
    This is gr8! Thanx a lot!

  14. Andres February 16th, 2009 7:29 AM

    Wooow, very well, many thanks!!!

  15. Foong March 12th, 2009 9:40 AM

    Thank you.

  16. matt April 23rd, 2009 8:33 PM

    How would you go about embedding an SWF into a word document?

  17. Walker April 23rd, 2009 10:31 PM

    Which version of Word you’re interested on? I am using Word 2007 now.

  18. Walker April 24th, 2009 1:37 AM

    @Matt, I have just published the guide of embedding SWF file into Word 2007.

  19. How To Embed SWF File Or Shockwave Flash Object In Microsoft Word 2007? April 26th, 2009 12:20 PM

    [...] and have fun with the embedded Shockwave Flash game in no time. (See also previous post on how to extract or retrieve the embedded SWF file in Microsoft Word or Excel) I am not sure the Microsoft Word or Excel Viewer can playback the embedded Shockwave Flash game, [...]

  20. Paul June 17th, 2009 7:17 PM

    Hi this is great VB work and very impressive indeed. I am trying to stop the embedded flash from running in Word on our network do you know a way of doing this?

    Paul

  21. Ron July 14th, 2009 3:20 PM

    Cool

  22. Vishnudas July 14th, 2009 5:09 PM

    Nice code ….
    working fine.
    Thnks

  23. nRI M.H.C.A July 25th, 2009 12:10 AM

    wow thats marvellous
    i have bin searching something to do this from ages

    thx a a lot n keep up the good work.

  24. Muhammad July 28th, 2009 12:53 PM

    It works! Thanks.

  25. van August 27th, 2009 2:01 AM

    Hi, I have problem viewing the swf file in m. word 2007. The swf box appear but it doesn’t move. Can I know what happened?

    Thanks.

  26. Cs September 11th, 2009 3:24 PM

    Excellent!
    I have been searching around for the solution, and this just works!
    A simple, clear and easy to understand step-by-step guide!

  27. san October 7th, 2009 8:49 PM

    great !!! thts what I was looking for since a long period of time…….. really cool…………..

  28. archtheo November 15th, 2009 6:16 PM

    Ευχαριστώ!
    Thank you!

  29. DrJPB November 19th, 2009 4:25 PM

    Great job & thanks for sharing.

    Regards.

  30. dONe December 2nd, 2009 6:33 PM

    Amazing. It works……

  31. Jugger December 16th, 2009 10:39 PM

    Excel-went shock… with a wave & a flash it was out. Wow!
    Many thanks. Season’s Greetings.

  32. Mohammad January 7th, 2010 2:10 AM

    Thanks a lot!!!

  33. Prateek Raman January 27th, 2010 9:13 PM

    Awesome dude… You save us from going insane in the office.

  34. François DURAND March 9th, 2010 11:42 PM

    Merci beaucoup. C’est exactement ce qu’il me fallait !

  35. kramero April 26th, 2010 3:30 PM

    great…!
    work perfectly….!

    thanks a lot….

  36. David Gimeno i Ayuso May 6th, 2010 7:45 PM

    Thank you! It works like a shot!

  37. Nikhil May 8th, 2010 10:16 PM

    AWESOME, man, thanks!
    I don’t have MS Office installed where i want to play this – open office doesn’t play them :(.
    So it’s always better to have it out in SWF itself!

  38. Whisper May 9th, 2010 7:01 PM

    Great! works nice.
    Note: to use this in Office 2007:
    Click the Microsoft Office Button , and then click Excel Options.
    In the Popular category, under Top options for working with Excel, select the Show Developer tab in the Ribbon check box, and then click OK.

    now the Developer toolbar appears, click it then click “Visual Basic” icon, then continue the above steps.

    Thanks for Emily :)

  39. spckl25 May 23rd, 2010 9:22 PM

    Its giving out of memory error at the below point

    ReDim swfArr(swfFileLen – 1)

    using vb6.3

  40. Yair Ben Amron June 18th, 2010 1:22 AM

    Thank you!
    This is great!

    Very good job!

  41. Jay June 28th, 2010 2:17 PM

    Just modified it a bit and can extract SWFs from any type of file. Any idea how to modify it to extract more than one embedded SWF?

  42. Ime August 13th, 2010 4:27 AM

    Thank you.

    It’s just what I needed.

    Bravo.