Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Help to Convert VBA Macro to VBS and Add Features

Status
Not open for further replies.

SkreeM

IS-IT--Management
Jun 6, 2005
117
GB
Hi Everyone,

I have recently performed a server upgrade at a clients site where we consolidated file servers and installed terminal services. We havn't got the smae file server anmes or shares any more. when the users open word documents that were greated from server based templateds that existed on servers that are no longer present it takes ages to try and find the template before opening the document. I have found a script(pasted below) in the microsoft article at this address
I need to know if i can turn this into a vbscript and also if i can make it do a couple of extra things. The script is designed to run thru all documents in one folder and change the server template path from the old to the new. I need to enhance this to allow for searching on 4 or 5 different existing template paths plus ideally i want to be able to set it off on one network drive and for it to go through all the files/folders doing every single one.

Any help would be most appreciated, i think i may be able to work the bit of cycling through subfolders out but i's still going to need help.

Thanks in advance for any advice.

Skr

Code:
Sub Test()
   Dim strFilePath As String 
   Dim strPath As String
   Dim intCounter As Integer
   Dim strFileName As String
   Dim OldServer As String
   Dim NewServer As String
   Dim objDoc As Document
   Dim objTemplate As Template
   Dim dlgTemplate As Dialog  

   OldServer = "<\\rsnj01\vol1>" 
   NewServer = "<\\rsnyc1p\vol3>" 
   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, 13)) = LCase(OldServer) Then        
            objDoc.AttachedTemplate = NewServer & Mid(strPath, 14)    
        End If    
         strFileName = Dir()    
         objDoc.Save                  
         objDoc.Close
      Loop  
   Set objDoc = Nothing
   Set objTemplate = Nothing
   Set dlgTemplate = Nothing  

End Sub
 
Put all your paths into an array. Call your sub and use the array data as an argument to the sub. The sub should read that valie of the folder from the array rather than prompt the user for it.

I hope you find this post helpful.

Regards,

Mark

Check out my scripting solutions at
Work SMARTER not HARDER. The Spider's Parlor's Admin Script Pack is a collection of Administrative scripts designed to make IT Administration easier! Save time, get more work done, get the Admin Script Pack.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top