Word MetaFile Data

JimmyC
3StarLounger
Posts: 379
Joined: 08 Feb 2010, 16:08

Word MetaFile Data

Post by JimmyC »

Please be patient as I am really out of my area with this question.

We currently use MS Word 2010---but from 2002 to 2011 my employer used Word XP. What is happening is that a sporadic number of Word files--that were created prior to 2011, reference a server that is no longer active (i.e. please see screen print below). Even a single page document with this server reference may take 30-45 seconds to open in Word 2010. Of course, it is more acute for longer documents (i.e. a 10 page document takes 3-4 minutes to open).

If I cleanse the metadata using Word 2010's document inspector on one of these documents and re-save the document---the lag in opening the document disappears. My preference would be to only remove the offending metafile field and not cleanse everything--but I don't know how to do this. We have almost 2 terabits worth of documents stored and I need to determine how many documents have this issue (i.e. where it seems to be looking to the "old" nonexistent server prior to opening the document.

So my questions are:
1. Is there anyway to query the Word documents to identify and "read" the metafile data without opening the document to determine which documents reference the old, non-existent server?

2. If I can do # 1, is there any way to "mass cleanse" these document are remove the reference field to the old, non-existent serve? And can I cleanse only the metafile field that causes the problem without cleansing all the fields?

3. Risks of doing the above on employer documents (i.e., could I corrupt them)?

One other small nuiance, we use a program called Worldox to manage all our documents---and I am hopeful that I can access the hard drive directly were the Word files are stored without disrupting Worldox document index, etc. THANKS.
You do not have the required permissions to view the files attached to this post.
Last edited by JimmyC on 28 Oct 2013, 15:36, edited 2 times in total.

User avatar
HansV
Administrator
Posts: 74445
Joined: 16 Jan 2010, 00:14
Status: Microsoft MVP
Location: Wageningen, The Netherlands

Re: Word MetaFile Data

Post by HansV »

To upload an image from your hard disk, upload it as an attachment to your post. If the attachment is a .gif, .jpg or .png file, it will automatically be displayed in the post.
Regards,
Hans

JimmyC
3StarLounger
Posts: 379
Joined: 08 Feb 2010, 16:08

Re: Word MetaFile Data

Post by JimmyC »

Hans---thanks for helping me get the image attached to the post. JimC

User avatar
HansV
Administrator
Posts: 74445
Joined: 16 Jan 2010, 00:14
Status: Microsoft MVP
Location: Wageningen, The Netherlands

Re: Word MetaFile Data

Post by HansV »

There is a programmer's tool that lets you view and edit document properties without actually opening the document: The Dsofile.dll files lets you edit Office document properties when you do not have Office installed.

Using this tool, it should be able to write code that loops through all documents in a folder (for example), inspects their properties and edits them if necessary. Writing such code is not easy, however, and since it will probably take several steps to get the code to do exactly what you want, it would be best to have someone 'on site' to work on it and to test it. I don't think it'd be feasible to develop such code remotely.

One other thing: whichever method you use, with 2 Terabits of documents, it's bound to take a loooong time to process them...
Regards,
Hans

JimmyC
3StarLounger
Posts: 379
Joined: 08 Feb 2010, 16:08

Re: Word MetaFile Data

Post by JimmyC »

Hans---as always, thank you for taking the time and also use your talents to help others. I am always grateful for your advice. I will check out the site you reference and, if needed, be back with a question or two.

Do you happen to know if it's possible using Word 2010, to cleanse only the errant field rather than doing what I am doing and cleansing everything? At least the "un-do's, etc. would not be erased to correct the errant server reference if I could cleanse only a single field--but I cannot locate any material using Google as to where the template reference is located in the metafile data.

Again thank you. JimC

User avatar
HansV
Administrator
Posts: 74445
Joined: 16 Jan 2010, 00:14
Status: Microsoft MVP
Location: Wageningen, The Netherlands

Re: Word MetaFile Data

Post by HansV »

Without seeing such a document - and I realize that you can't make them available - it is impossible for me to know where the reference to the server resides, and hence to suggest a way to remove it.
Regards,
Hans

User avatar
macropod
4StarLounger
Posts: 487
Joined: 17 Dec 2010, 03:14

Re: Word MetaFile Data

Post by macropod »

When templates other than Word’s Normal template are used to create a document, the template’s path & name are stored with the document. If that path is a network path, a change to the server name will break the link. The result can be significant delays in opening the documents on the new server. See: http://support.microsoft.com/?kbid=830561" onclick="window.open(this.href);return false;. The same effect occurs when the file is opened on a computer attached to a different network. The following macro can be used to update the template paths or, if a new template path can’t be found, to point it to Word’s Normal template. Code is included to restore the original date/time stamps of the updated files.
In the code, simply replace however much of the old & new template paths differ in the variables ‘OldServer, and ‘NewServer’.

Code: Select all

Option Explicit
Dim FSO As Object 'a FileSystemObject
Dim oFolder As Object 'the folder object
Dim oSubFolder As Object 'the subfolders collection
Dim oFiles As Object 'the files object
Dim i As Long, j As Long
'
Sub Main()
' Minimise screen flickering
Application.ScreenUpdating = False
Dim StrFolder As String
' Browse for the starting folder
StrFolder = GetTopFolder
If StrFolder = "" Then Exit Sub
i = 0: j = 0
' Search the top-level folder
Call GetFolder(StrFolder & "\")
' Search the subfolders for more files
Call SearchSubFolders(StrFolder)
' Return control of status bar to Word
Application.StatusBar = ""
' Restore screen updating
Application.ScreenUpdating = True
MsgBox i & " of " & j & " files updated.", vbOKOnly
End Sub
'
Function GetTopFolder() As String
GetTopFolder = ""
Set oFolder = CreateObject("Shell.Application").BrowseForFolder(0, "Choose a folder", 0)
If (Not oFolder Is Nothing) Then GetTopFolder = oFolder.Items.Item.Path
Set oFolder = Nothing
End Function
'
Sub SearchSubFolders(strStartPath As String)
If FSO Is Nothing Then Set FSO = CreateObject("Scripting.FileSystemObject")
Set oFolder = FSO.GetFolder(strStartPath)
Set oSubFolder = oFolder.subfolders
For Each oFolder In oSubFolder
  Set oFiles = oFolder.Files
  ' Search the current folder
  Call GetFolder(oFolder.Path & "\")
  ' Call ourself to see if there are subfolders below
  Call SearchSubFolders(oFolder.Path)
Next
Set FSO = Nothing
End Sub
'
Sub GetFolder(StrFolder As String)
Dim strFile As String
strFile = Dir(StrFolder & "*.doc")
' Process the files in the folder
While strFile <> ""
  ' Update the status bar is just to let us know where we are
  Application.StatusBar = StrFolder & strFile
  Call UpdateTemplateRefs(StrFolder & strFile)
  strFile = Dir()
Wend
End Sub
'
Sub UpdateTemplateRefs(strDoc As String)
' This sub updates the template paths for files after a server
' change. Simply insert however much of the lower end of the
' server paths differ as the OldServer and NewServer variables.
Dim OldServer As String, NewServer As String, strPath As String
Dim oItem As Object, StrDtTm As String
OldServer = "\\TSB\VOL1": NewServer = "\\TSLSERVER\Files"
' Store the file's current Date/Time stamp.
If FSO Is Nothing Then Set FSO = CreateObject("Scripting.FileSystemObject")
Set oItem = FSO.GetFile(strDoc)
StrDtTm = oItem.DateLastModified
' Open the document
Documents.Open strDoc, AddToRecentFiles:=False, ReadOnly:=False, Format:=wdOpenFormatAuto
With ActiveDocument
  If .ProtectionType = wdNoProtection Then
    ' Update the template path
    strPath = Dialogs(wdDialogToolsTemplates).Template
    If LCase(Left(strPath, Len(OldServer))) = LCase(OldServer) Then
      ' Update the file counter for changed files
      i = i + 1
      ' Get the new template path & name
      strPath = NewServer & Mid(strPath, Len(OldServer) + 1)
      ' Check whether the template exists
      If Dir(strPath) <> "" Then
        ' If found, update the path
        .AttachedTemplate = NewServer & Mid(strPath, Len(OldServer) + 1)
      Else
        ' If not found, reset the template to 'Normal'
        .AttachedTemplate = ""
        ' Output an error report in the document from which the macro is run.
        ThisDocument.Range.InsertAfter vbCr & "Template: " & strPath & " not found for " & strDoc
      End If
    End If
  Else
    ' Output a 'protected' file report in the document from which the macro is run.
    ThisDocument.Range.InsertAfter vbCr & strDoc & " protected. Not updated."
  End If
  .Close SaveChanges:=True
End With
' Update the main file counter
j = j + 1
' Let Word do its housekeeping
DoEvents
' Reset the file's Date/Time stamp.
Set oItem = FSO.GetFile(strDoc)
If oItem.DateLastModified <> StrDtTm Then oItem.DateLastModified = StrDtTm
Set oItem = Nothing
End Sub
You can determine how much of the old & new template paths differ, for the purposes of the ‘OldServer, and ‘NewServer’ variables with code like the following, which you can run on a document created on the old server and another created on the new server, both referencing the same template.

Code: Select all

Sub GetTemplateRef()
With ActiveDocument
  MsgBox Dialogs(wdDialogToolsTemplates).Template
End With
End Sub
Paul Edstein
[Fmr MS MVP - Word]

JimmyC
3StarLounger
Posts: 379
Joined: 08 Feb 2010, 16:08

Re: Word MetaFile Data

Post by JimmyC »

Paul---thank you. I am off to digest your code and advice. I maybe back with questions. Again, thank you. JimC

JimmyC
3StarLounger
Posts: 379
Joined: 08 Feb 2010, 16:08

Re: Word MetaFile Data

Post by JimmyC »

Paul--One issue in working with the code--when a Word document is password protected, and I don't know the password, the macro halts. Is there any way the macro can be adjusted to "skip" a word document that is password protected? Thanks. JimC

User avatar
HansV
Administrator
Posts: 74445
Joined: 16 Jan 2010, 00:14
Status: Microsoft MVP
Location: Wageningen, The Netherlands

Re: Word MetaFile Data

Post by HansV »

Change the UpdateTemplateRefs procedure as follows:

Code: Select all

Sub UpdateTemplateRefs(strDoc As String)
' This sub updates the template paths for files after a server
' change. Simply insert however much of the lower end of the
' server paths differ as the OldServer and NewServer variables.
Dim OldServer As String, NewServer As String, strPath As String
Dim oItem As Object, StrDtTm As String
OldServer = "\\TSB\VOL1": NewServer = "\\TSLSERVER\Files"
' Store the file's current Date/Time stamp.
If FSO Is Nothing Then Set FSO = CreateObject("Scripting.FileSystemObject")
Set oItem = FSO.GetFile(strDoc)
StrDtTm = oItem.DateLastModified
' Open the document
On Error GoTo ErrHandler
Documents.Open strDoc, AddToRecentFiles:=False, ReadOnly:=False, Format:=wdOpenFormatAuto, _
  PasswordDocument:="!@#$%^&*()_" ' a nonsense password
On Error GoTo 0
With ActiveDocument
  If .ProtectionType = wdNoProtection Then
    ' Update the template path
    strPath = Dialogs(wdDialogToolsTemplates).Template
    If LCase(Left(strPath, Len(OldServer))) = LCase(OldServer) Then
      ' Update the file counter for changed files
      i = i + 1
      ' Get the new template path & name
      strPath = NewServer & Mid(strPath, Len(OldServer) + 1)
      ' Check whether the template exists
      If Dir(strPath) <> "" Then
        ' If found, update the path
        .AttachedTemplate = NewServer & Mid(strPath, Len(OldServer) + 1)
      Else
        ' If not found, reset the template to 'Normal'
        .AttachedTemplate = ""
        ' Output an error report in the document from which the macro is run.
        ThisDocument.Range.InsertAfter vbCr & "Template: " & strPath & " not found for " & strDoc
      End If
    End If
  Else
    ' Output a 'protected' file report in the document from which the macro is run.
    ThisDocument.Range.InsertAfter vbCr & strDoc & " protected. Not updated."
  End If
  .Close SaveChanges:=True
End With

ExitHandler:
' Update the main file counter
j = j + 1
' Let Word do its housekeeping
DoEvents
' Reset the file's Date/Time stamp.
Set oItem = FSO.GetFile(strDoc)
If oItem.DateLastModified <> StrDtTm Then oItem.DateLastModified = StrDtTm
Set oItem = Nothing
Exit Sub

ErrHandler:
Select Case Err
  Case 5408 ' password-protected
    ThisDocument.Range.InsertAfter vbCr & strDoc & " was password-protected. Document skipped."
  Case Else ' other error
    ThisDocument.Range.InsertAfter vbCr & "An error occurred while opening " & strDoc & ". Document skipped."
End Select
Resume ExitHandler
End Sub
Regards,
Hans

JimmyC
3StarLounger
Posts: 379
Joined: 08 Feb 2010, 16:08

Re: Word MetaFile Data

Post by JimmyC »

Hans--thanks---off to give it a try. Thanks again. Jim