Konu: Word Template Değişikliği
Arkadaşlar network üzerinde bulunan antetli yazılar için ortak bir alanda Microsoft Word Template file'ları kullanılıyor. Bu template'ler kullanılarak hazırlanan word dökümanlarını evinizde veya template'in bulunduğu server'a erişim olmadığı bir yerde açmaya çalıştığınızda word uzun bir süre bekletiyor (server ve template dosyasını arıyor) bulamayınca da normal açıyor. Word 2003 niçin beklettiğini yazmıyor ama word 2007'de server'a erişimi sağlamaya çalıştığını en alt satırda yazarak bekletiyor. Kısaca sorum şu:
Eski server üzerindeki template'ler baz alınarak yazılmış dosyalara kaydedilmiş olan template yol bilgisini yeni server göstererek nasıl değiştirebiliriz.
İnternette VB ile yazılmış aşağıdaki 2 scripti buldum. Bunu VFP 9'da yapabilir miyiz diye sormak istedim. 1. script belirttiğiniz klasör ve alt klasörlerdeki tüm .doc dosyalarını tarıyor, template tanım bilgisinde ESKİSERVER tanımlı templatelerin ismini YENİSERVER olarak değiştirip kaydediyor. Hata vermedi ama isteneni de yapmadı. 2. script ise isteneni yapıyor ama her bir .dot template'i için ayrı ayrı yapmak gerekiyor, template klasörüne göre değil, template dosyasına göre çalışıyor. Umarım sorunu anlatabilmişimdir.
İlgilenen olursa şimdiden teşekkürler.
1. Script
---------
Sub ChangeTemplates()
FindFiles "C:\DocumentFolders", "*.doc"
End Sub
Sub FindFiles(strFolder As String, strFilePattern As String)
Dim strFileName As String
Dim strFolders() As String
Dim iFolderCount As Integer
Dim i As Integer
'collect child folders
strFileName = Dir$(strFolder & "\", vbDirectory)
Do Until strFileName = ""
If (GetAttr(strFolder & "\" & strFileName) And vbDirectory) = vbDirectory Then
If Left$(strFileName, 1) <> "." Then
ReDim Preserve strFolders(iFolderCount)
strFolders(iFolderCount) = strFolder & "\" & strFileName
iFolderCount = iFolderCount + 1
End If
End If
strFileName = Dir$()
Loop
'process files in current folder
strFileName = Dir$(strFolder & "\" & strFilePattern)
Do Until strFileName = ""
DoEvents
Documents.Open strFolder & "\" & strFileName
If ActiveDocument.AttachedTemplate.Path = "\\Oldserver\templates\" Then
ActiveDocument.AttachedTemplate = "\\NewServer\templates\" & ActiveDocument.AttachedTemplate.Name
ActiveDocument.Close wdSaveChanges
Else
ActiveDocument.Close wdDoNotSaveChanges
End If
strFileName = Dir$()
Loop
'look through child folders
For i = 0 To iFolderCount - 1
FindFiles strFolders(i), strFilePattern
Next i
End Sub
2. Script
--------------
Sub FindFiles(strFolder As String, strFilePattern As String)
Dim strFileName As String
Dim strFolders() As String
Dim iFolderCount As Integer
Dim i As Integer
'collect child folders
strFileName = Dir$(strFolder & "\", vbDirectory)
Do Until strFileName = ""
If (GetAttr(strFolder & "\" & strFileName) And vbDirectory) = vbDirectory Then
If Left$(strFileName, 1) <> "." Then
ReDim Preserve strFolders(iFolderCount)
strFolders(iFolderCount) = strFolder & "\" & strFileName
iFolderCount = iFolderCount + 1
End If
End If
strFileName = Dir$()
Loop
'process files in current folder
strFileName = Dir$(strFolder & "\" & strFilePattern)
Do Until strFileName = ""
DoEvents
Documents.Open strFolder & "\" & strFileName
If ActiveDocument.AttachedTemplate.Name <> "Normal.Dot" Then
ActiveDocument.AttachedTemplate = "\\NewServer\Company\Sales\Quote Templates\" & ActiveDocument.AttachedTemplate.Name
ActiveDocument.Close wdSaveChanges
Else
ActiveDocument.Close wdDoNotSaveChanges
End If
strFileName = Dir$()
Loop
'look through child folders
For i = 0 To iFolderCount - 1
FindFiles strFolders(i), strFilePattern
Next i
End Sub
Private Sub CommandButton1_Click()
MsgBox ("Start")
FindFiles "C:\Company\Sales\Master Quote File", "*.doc"
MsgBox ("Completed")
End Sub