We have just discovered a problem with thousands of Word documents after switching off an old server. The problem relates to old Word 97 documents still trying to reference the old template location. The Microsoft KB article 830561 describes the problem and a workaround solution via method 4.
I am wondering if I can somehow port this VB script into a Kix script to run against our files. While I am familiar with most of the VB commands there are some that I do not know the Kix exquivalent if any.
This is the VB code supplied by Microsoft
Code:
Sub Test()
Dim strFilePath As String
Dim strPath As String
Dim intCounter As Integer
Dim strFileName As String
Dim OldServer As String
Dim objDoc As Document
Dim objTemplate As Template
Dim dlgTemplate As Dialog
Dim nServer As Integer
'hardcode the name of the old server.
OldServer = "{enter the name of the Old Server}"
nServer = Len(OldServer)
strFilePath = InputBox("What is the folder location that you want to use?")
If Right(strFilePath, 1) <> "\" Then strFilePath = strFilePath & "\"
strFileName = Dir(strFilePath & "*.doc")
Do While strFileName <> ""
Set objDoc = Documents.Open(strFilePath & strFileName)
Set objTemplate = objDoc.AttachedTemplate
Set dlgTemplate = Dialogs(wdDialogToolsTemplates)
strPath = dlgTemplate.Template
If LCase(Left(strPath, nServer)) = LCase(OldServer) Then
objDoc.AttachedTemplate = NormalTemplate
End If
strFileName = Dir()
objDoc.Save
objDoc.Close
Loop
Set objDoc = Nothing
Set objTemplate = Nothing
Set dlgTemplate = Nothing
End Sub
This is my attempt, have not tested it as I know there are likely to be errors.
Code:
Function Test()
Dim $strFilePath
Dim $strPath
Dim $intCounter
Dim $strFileName
Dim $OldServer
Dim $objDoc
Dim $objTemplate
Dim $dlgTemplate
Dim $nServer
;'hardcode the name of the old server.'
$Form = CreateObject("Kixtart.Form")
$OldServer = "old server name here"
$nServer = Len($OldServer)
$strFilePath = $Form.InputBox("What is the folder location that you want to use?")
If Right($strFilePath, 1) <> "\" $strFilePath = $strFilePath + "\" EndIf
$strFileName = Dir($strFilePath + "*.doc")
Do While $strFileName <> ""
$objDoc = Documents.Open($strFilePath + $strFileName)
$objTemplate = objDoc.AttachedTemplate
$dlgTemplate = Dialogs(wdDialogToolsTemplates)
$strPath = dlgTemplate.Template
If Lcase(Left($strPath, $nServer)) = Lcase($OldServer)
$rc = objDoc.AttachedTemplate = NormalTemplate
EndIf
$strFileName = Dir()
$rc = objDoc.Save
$rc = objDoc.Close
Loop
$objDoc = ""
$objTemplate = ""
$dlgTemplate = ""
EndFunction
Any help would be appreciated.
Cheers,
Grasshopper75