#1
|
|||
|
|||
File compression
I am working with Windows XP and Office 2010. I am attempting to compress an excel file (.xlsx). I need to access the file directory structure, so the compressed file should give me the option to 'extract all' when I right click the file. The instructions I'm following (from a book) say to append .zip to the end of the file name in the file properties window. The file name should then be 'file_name.xlsx.zip'. This, however, does not compress the file. I've attempted a couple of other ways to compress the file with no luck. Any suggestions? |
#2
|
||||
|
||||
Hi OfficeNinja,
The native file formats for Office 2007 & later already uses zip compression. The docx, xlsx, etc extensions are there so that Windows knows which applications to open them with. Applying further compression won't achieve much - and could actually increase the file size due to the space required for storing the compressor's file tokens. If you change the docx, xlsx, etc extensions to zip, you can then use other software to examine these files' internal structure.
__________________
Cheers, Paul Edstein [Fmr MS MVP - Word] Last edited by macropod; 03-11-2012 at 12:41 AM. Reason: typo |
#3
|
|||
|
|||
Paul, thanks for the reply. If the file were already compressed the 'extract all' option would be available. I attempted to change the file name extension to simply .zip and the directory is still hidden.
Do you happen to know any other form of accessing the directory structure? O.N. |
#4
|
||||
|
||||
Hi OfficeNinja,
What are you trying to view the structure with? I don't know what directory structure you're especting to see, but it's a very simple affair. With the method I described, using WinZip on a basic document reveals the following folders: _rels\ word\_rels\ docProps\ word\ word\theme
__________________
Cheers, Paul Edstein [Fmr MS MVP - Word] |
#5
|
|||
|
|||
Exactly, I need to access the the xlm files in the a_rels folder. I understand windows xp has native compression capabilities. I might try winzip, though there might be a way around having to install software by having windows do it. idk
|
#6
|
||||
|
||||
I can't see what that has to do with compressing the xlsx file though, as that would make the xm lfiles even less accessible. If anything, extracting the file means de-compressing the file, for which see: http://www.jkp-ads.com/articles/Exce...leFormat02.asp
__________________
Cheers, Paul Edstein [Fmr MS MVP - Word] Last edited by macropod; 03-02-2012 at 06:07 PM. |
#7
|
|||
|
|||
Because, as far as I know, the only way to access the 'extract all' option is first compress the file. Extraction can only be accomplished on a compressed file.
Thanks for the link! I'm going to try that out. |
#8
|
||||
|
||||
Not with an Office 2007+ file format. As I said before, these are already zip archives - they just have a different extension. So, if you wanted to access the 'extract all' option, all you need to do is to explicitly open the files with a program like WinZip or change the file extension to zip so that you can do the extraction. Compressing the files beforehand will mean the only thing you can extract is the xlsx archive as a single file - it won't give you access to that file's internal structure.
__________________
Cheers, Paul Edstein [Fmr MS MVP - Word] |
#9
|
||||
|
||||
Hi OfficeNinja,
I've lately had occasion to delve into extracting data from Office 2007 files. The following macro is based on that work. It probably does far more than you need. I can also be run from any Office 2007/2010 application, as none of the code is application-specific. After selecting the folder to process, the code extracts all files in each xlsx/xlsm file's _rels\ folder and outputs them to a new 'XlRels' folder in the parent folder. Each output file's name is prefixed with the parent file's name. If you want to extract data from just one file, the easiest way would be to put in into a folder on its own, then point the macro to that folder. Code:
Sub ExtractXlRels() Application.ScreenUpdating = False Dim SBar As Boolean ' Status Bar flag Dim StrInFold As String, StrOutFold As String, StrTmpFold As String Dim StrDocFile As String, StrZipFile As String, Obj_App As Object, i As Long Dim StrFile As String, StrFileList As String, StrMediaFile As String, j As Long StrInFold = GetFolder If StrInFold = "" Then Exit Sub ' Store current Status Bar status, then switch on SBar = Application.DisplayStatusBar Application.DisplayStatusBar = True StrOutFold = StrInFold & "\XlRels" StrTmpFold = StrInFold & "\Tmp" 'Test for existing tmp & output folders, create they if they don't already exist If Dir(StrTmpFold, vbDirectory) = "" Then MkDir StrTmpFold If Dir(StrOutFold, vbDirectory) = "" Then MkDir StrOutFold 'Create a Shell App for accessing the zip archives Set Obj_App = CreateObject("Shell.Application") 'Look for docx files to process StrFile = Dir(StrInFold & "\*.xls?", vbNormal) 'Build the file list While StrFile <> "" StrFileList = StrFileList & "|" & StrFile StrFile = Dir() Wend 'process the file list j = UBound(Split(StrFileList, "|")) For i = 1 To j 'ID the document to process StrDocFile = StrInFold & "\" & Split(StrFileList, "|")(i) ' Report progress on Status Bar. Application.StatusBar = "Processing file " & i & " of " & j & ": " & StrDocFile 'Define the zip name StrZipFile = Split(StrDocFile, ".")(0) & ".zip" 'In case the file is in use or zip file has no media On Error Resume Next 'Create the zip file, by simply copying to a new file with a zip extension FileCopy StrDocFile, StrZipFile 'Extract the zip archive's media files to the temporary folder Obj_App.NameSpace(StrTmpFold & "\").CopyHere Obj_App.NameSpace(StrZipFile & "\_rels\").Items 'Delete the zip file - the loop takes care of timing issues Do While Dir(StrZipFile) <> "" Kill StrZipFile Loop 'Restore error trapping On Error GoTo 0 'Get the temporary folder's file listing StrMediaFile = Dir(StrTmpFold & "\*.*", vbNormal) 'Process the temporary folder's files While StrMediaFile <> "" 'Copy the file to the output folder, prefixed with the source file's name FileCopy StrTmpFold & "\" & StrMediaFile, StrOutFold & "\" & Split(Split(StrFileList, "|")(i), ".")(0) & StrMediaFile 'Delete the media file Kill StrTmpFold & "\" & StrMediaFile 'Get the next media file StrMediaFile = Dir() Wend Next 'Delete the temporary folder RmDir StrTmpFold ' Clear the Status Bar Application.StatusBar = False ' Restore original Status Bar status Application.DisplayStatusBar = SBar Application.ScreenUpdating = True End Sub Function GetFolder() As String Dim oFolder As Object GetFolder = "" Set oFolder = CreateObject("Shell.Application").BrowseForFolder(0, "Choose a folder", 0) If (Not oFolder Is Nothing) Then GetFolder = oFolder.Items.Item.Path Set oFolder = Nothing End Function
__________________
Cheers, Paul Edstein [Fmr MS MVP - Word] |
Thread Tools | |
Display Modes | |
|
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
error: You are attempting to save a file format that is blocked by file block setting | zatlas1 | Office | 8 | 04-28-2012 02:37 PM |
Outlook and compression | seandempsey | Outlook | 0 | 12-04-2010 02:57 AM |
Video compression in XP vs Windows 7? | judderbones | PowerPoint | 2 | 11-18-2010 11:28 AM |
File compression recommendation | bb80 | Office | 1 | 08-13-2009 10:58 AM |