1

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

2 Son düzenleyen, cetinbasoz (03.03.2011 14:59:35)

Re: Word Template Değişikliği

Scriptlerin tercumesi degil tam, test de etmedim:


Visual Fox Pro
Local strFolder, lcDocName, oWord, oldFolder, newFolder

 
oldFolder = " eski dosya dizini "
newFolder = " yeni dosya dzini "
 
strFolder = Getdir()
GetTree(m.strFolder,'*.doc')
 
#DEFINE wdDoNotSaveChanges    0   
#DEFINE wdSaveChanges    -1   
#DEFINE wdPromptToSaveChanges    -2   
 
oWord = Createobject('Word.Application')
 
Select FileList
Scan
  lcDocName = Addbs(Trim(filepath))+Trim(filename)
  oWord.Documents.Open( m.lcDocName )
  With .ActiveDocument
 
    If .AttachedTemplate.Name <> "Normal.Dot" And ;
        UPPER(Addbs(.AttachedTemplate.Path)) == Upper(Addbs(m.oldFolder))
      .AttachedTemplate = Forcepath( .AttachedTemplate.Name, m.newFolder )
      .Close(wdSaveChanges)
 
      ? "Degisti", m.lcDocName
    Else
      .Close(wdDoNotSaveChanges)
    Endif
  Endwith
ENDSCAN
 
oWord.Quit()
MESSAGEBOX("Tamam herhalde")
 
 
Function GetTree
Lparameters tcStartDir, tcSkeleton
tcSkeleton = Evl(m.tcSkeleton, "*.*")
Create Cursor FileList ;
  (filepath m, filename m, filesize i, ;
  fattr c(8), createtime T, lastacc T, lastwrite T)
 
Create Cursor folderlist (filepath m)
oFiler = Createobject('filer.fileutil')
With oFiler
  .SearchPath = m.tcStartDir
  .Subfolder = 1
  .FileExpression = m.tcSkeleton
  .Find(0)
  For ix=1 To .Files.Count
    With .Files(ix)
 
      Insert Into FileList ;
        (filepath, filename, filesize, fattr, createtime, lastacc, lastwrite)  ;
        values ;
        (.Path, .Name, .Size, Attr2Char(.Attr), ;
        Num2Time2(.Datetime), Num2Time2(.LastAccessTime), Num2Time2(.LastWriteTime) )
 
    Endwith
  Endfor
  Return .Files.Count
Endwith
Endfunc
 
Function Num2Time2
Lparameters tnFloat
Return Dtot(Date(1899,12,30) + m.tnFloat)
Endfunc
 
Function Attr2Char
Lparameters tnAttr
Return ;
  IIF(Bittest(tnAttr,0),'RO','RW')+;
  IIF(Bittest(tnAttr,1),'H','_')+;
  IIF(Bittest(tnAttr,2),'S','_')+;
  IIF(Bittest(tnAttr,4),'D','_')+;
  IIF(Bittest(tnAttr,5),'A','_')+;
  IIF(Bittest(tnAttr,6),'E','_')+;
  IIF(Bittest(tnAttr,7),'N','_')
Endfunc

3

Re: Word Template Değişikliği

Yarin test ederim hocam, eline saglik.

4

Re: Word Template Değişikliği

Sadece   With oWord.ActiveDocument satırını değiştirince oldu ve istediğim gibi çalıştı Hocam. Elinize ve beyninize sağlık, hakkınız ödenemez sizin. Hatta yeni path yeri kaydetmektense template path bilgisini de iptal ettirdim, çok güzel oldu. Çok teşekkürler.