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 29-05-08@19:10

    Bravo… excellent.. :)

  2. Chikz 20-06-08@17:38

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

  3. Bypass Exchange Server Attachment Filtering System – Walker News 24-06-08@18:49

    […] 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 01-08-08@22:19

    Very fine work..
    Great computer genius.

  5. raghu 09-08-08@22:00

    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 01-09-08@02:07

    Thanks a lot for this works great

  7. SWF-Extractor: A Hungarian Freeware To Extract SWF From Microsoft Excel And Word Document – Walker News 12-09-08@00:36

    […] 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 15-09-08@21:39

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

  9. Bamoi 03-11-08@00:39

    U are a genius!!! thx man

  10. Alonso 27-11-08@23:40

    Great men, so helpfull

    Alonso From Ecuador

  11. Thiago 06-12-08@01:04

    Fantastic dude!

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

    Thanks

    Thiago from Brazil

  12. KumC 10-01-09@06:39

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

  13. Suz 10-02-09@14:21

    Superb job…
    This is gr8! Thanx a lot!

  14. Andres 16-02-09@07:29

    Wooow, very well, many thanks!!!

  15. Foong 12-03-09@09:40

    Thank you.

  16. matt 23-04-09@20:33

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

  17. Walker 23-04-09@22:31

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

  18. Walker 24-04-09@01:37

    @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? 26-04-09@12:20

    […] 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 17-06-09@19:17

    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 14-07-09@15:20

    Cool

  22. Vishnudas 14-07-09@17:09

    Nice code ….
    working fine.
    Thnks

  23. nRI M.H.C.A 25-07-09@00:10

    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 28-07-09@12:53

    It works! Thanks.

  25. van 27-08-09@02:01

    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 11-09-09@15:24

    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 07-10-09@20:49

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

  28. archtheo 15-11-09@18:16

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

  29. DrJPB 19-11-09@16:25

    Great job & thanks for sharing.

    Regards.

  30. dONe 02-12-09@18:33

    Amazing. It works……

  31. Jugger 16-12-09@22:39

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

  32. Mohammad 07-01-10@02:10

    Thanks a lot!!!

  33. Prateek Raman 27-01-10@21:13

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

  34. François DURAND 09-03-10@23:42

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

  35. kramero 26-04-10@15:30

    great…!
    work perfectly….!

    thanks a lot….

  36. David Gimeno i Ayuso 06-05-10@19:45

    Thank you! It works like a shot!

  37. Nikhil 08-05-10@22:16

    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 09-05-10@19:01

    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 23-05-10@21:22

    Its giving out of memory error at the below point

    ReDim swfArr(swfFileLen – 1)

    using vb6.3

  40. Yair Ben Amron 18-06-10@01:22

    Thank you!
    This is great!

    Very good job!

  41. Jay 28-06-10@14:17

    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 13-08-10@04:27

    Thank you.

    It’s just what I needed.

    Bravo.

  43. tanmay 05-12-10@17:35

    error is coming:

    Compile error
    method or data member not found

  44. Rachit 12-01-11@04:22

    Excellent work!!!!
    really very helpful!!!

    Thanx a Ton!!!

  45. Ricky 16-02-11@09:52

    Is &H57 and &H53 the header of the swf file format?
    I was hoping to extract different file types that are embedded OLE’s as well – but am not sure how to identify them.

    Also, what does the &H46 indicate?

  46. Ricky 16-02-11@09:55

    Jay,

    Not sure if this will go through….
    It’s rare to have multiple flash files in an office file, but this should get them all…

    Public Sub ExtractEmbed()
    
    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
    Dim OutCount As Integer
    
    
    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
                OutCount = OutCount + 1
                myFileId = FreeFile
                swfFileName = Left(tmpFileName, Len(tmpFileName) - 4) & "_" & OutCount & ".swf"
                Open swfFileName For Binary As #myFileId
                Put #myFileId, , swfArr
                Close myFileId
          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 as [ " & tmpFileName & " ]"
    
    End Sub
    
  47. Morpheus 28-03-11@22:02

    Great code, thank you very much.
    You may deserve to get the red capsule.

  48. SPD 14-04-11@16:43

    Great job,

    Also, useful in the new Adobe flash file exploits using doc files.

  49. mtvgp 14-05-11@04:23

    Excellent – what a time-saver!
    I had a swf in a ppt slide so I simply copied/pasted the object to an xls file, followed the instructions above with the new xls file and voila!

  50. bharath 08-12-11@00:13

    getting “method or data member not found” error …:(

    please help me

  51. GoJoJo 22-05-12@03:07

    When it saves as a .swf it saves with 0kb and when I try to open it in another program it doesn’t play. Any suggestions?

    Thanks

  52. Mart 15-06-12@12:39

    I used to have a program that removed Flash from Powerpoint, but now it doesn’t work in Windows 7.

    Any chance you could alter this to make it function in powerpoint?

  53. Prashant Saxena 31-07-12@18:25

    Awesome coding…
    Loved it..
    :-)

2014  •  Privacy Policy