VBA script assistance

duderoo

Expert Member
Joined
Jun 7, 2005
Messages
3,376
Reaction score
241
Location
Earth
I have a script below that will change the server name in all the documents from x to y as we have moved servers and as a result the documents are still looking at the old server.

Can anyone help here to set this up to enable me to run the script and point out where to put the old server name and new?

http://support.microsoft.com/kb/830561/en-us?spid=2530&sid=36

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
 
server name is here

OldServer = "<\\rsnj01\vol1>"
NewServer = "<\\rsnyc1p\vol3>"

to run save as a *.vbs and double click
 
Hmm this one confused me when i went through the replies,then I tore into that code thinking it was vbs >.>

This is a VBA macro,you need to open the Visual basic macro editor in your Office application,modify and then "Run" the code once it's Saved
 
Hmm this one confused me when i went through the replies,then I tore into that code thinking it was vbs >.>

This is a VBA macro,you need to open the Visual basic macro editor in your Office application,modify and then "Run" the code once it's Saved

That's right....is there perhaps some vba script that will do what I need?
 
That code you linked came directly from microsoft purpose-made to change server names in documents pointing to templates,you mean this isn't what you needed? Then your information supplied is insufficient
 
Yes I need to change the server name in the documents from x to y.
 
Maybe not what you need, but would it not be easier to just create a DNS pointer using the old server name and new server IP address?

Then the setting in the doc, pointing to the old server, can remain unchanged, and DNS can resolve the issue.
 
Last edited:
Choose a doc pointing to wrong server,open macro editor,paste code into it,change server names in
Code:
OldServer = "<\\rsnj01\vol1>"
NewServer = "<\\rsnyc1p\vol3>"
Run macro?
 
Choose a doc pointing to wrong server,open macro editor,paste code into it,change server names in
Code:
OldServer = "<\\rsnj01\vol1>"
NewServer = "<\\rsnyc1p\vol3>"
Run macro?

For each and every doc?
 
Maybe not what you need, but would it not be easier to just create a DNS pointer using the old server name and new server IP address?

Conradl that sounds like a good idea.

If the new server is say 192.168.3.3 and name XYZ and the old is say 192.168.3.4 and name ABC, what would I need to do?

So when looking for ABC it will point to 192.168.3.3?

Can you tell me what to do please?
 
You can test it by modifying your hosts file: C:\WINDOWS\system32\drivers\etc\hosts (note it has no extension, open it in notepad).
Add an entry like this to the bottom of the file, and save it:

192.168.3.3 ABC


Then ping ABC, (from the same machine that you modified the hosts file) - you should get a response back from 192.168.3.3. If this works try to open your document and see if the links work correctly. If they do, then you need to update your DNS settings so that all users get the settings.

Will cover the DNS later, if the hosts file works.
 
You can test it by modifying your hosts file: C:\WINDOWS\system32\drivers\etc\hosts (note it has no extension, open it in notepad).
Add an entry like this to the bottom of the file, and save it:

192.168.3.3 ABC


Then ping ABC, (from the same machine that you modified the hosts file) - you should get a response back from 192.168.3.3. If this works try to open your document and see if the links work correctly. If they do, then you need to update your DNS settings so that all users get the settings.

Will cover the DNS later, if the hosts file works.

Hi Conradl works perfectly.....now the DNS?

I assume I can just push that host file out to everyone as well, but DNS would be easier.

Just checked and I have an entry for the DNS already for that server name and it is pointing to 3.1. Can I assume I can just point it to 3.3 i won't break anything.
 
Last edited:
Rather use DNS, it is much easier to manage. If the old pointer is still there, then simply update it manually to point to the new server IP; you will then have two pointers, each with a different server name, pointing to the same IP address.

Glad you came right :)
 
Top
Sign up to the MyBroadband newsletter
X