Creating a Word file

G

Graham944

I have written a macro running on MS Project 2000 to write to a Word 2000
document running on Windows NT4. The macro works well except that it often (
but not always)fails if an attempt is made to rerun it. To clear the problem
I have to open the document in Word and then close it.

The essential lines of the macro are

Sub WordLinkTest()
Dim wdDocument As Word.Document

'open the Word document
Set wdDocument = GetObject("c:/WordLinkTest.doc")

'clear the document
wdDocument.Select
wdDocument.Application.Selection.Cut

'create the table
wdDocument.Tables.Add Range:=wdDocument.Application.Selection.Range,
NumRows:=1, NumColumns:=7

'set the column width
wdDocument.Tables(1).Columns(1).PreferredWidthType =
wdPreferredWidthPoints
wdDocument.Tables(1).Columns(1).PreferredWidth = _
CentimetersToPoints(1.2) 'FAILS ON THIS LINE
' with error 462
' "The remote server machine
does not exist or is unavailable"

wdDocument.Close savechanges:=True
Set wdDocument = Nothing
End Sub

Any ideas please,
Graham
 
R

Rod Gill

Try:
Sub WordLinkTest()
Dim wdApp as Word.Application
Dim wdDocument As Word.Document

Set wdApp=CreateObject("Word.Application")

'open the Word document
Set wdDocument = wdApp.Documents.Add

I think that's it but I haven't tested. Creating a new document each time
then saving and over-writing teh original may well be more reliable.

Have you thought of upgrading???!
 
G

Graham944

Rod:
That seems to have solved it thanks.

Unfortunately the system I am using is my employer's standard - at home I
have Project 2003 and Windows XP

Thanks,
Graham.>
 
R

Rod Gill

Try suggesting to him that every year he fails to update probably costs him
in productivity enough money to buy everyone a new computer and the latest
software practically every 3 months. And if someone leaves because they want
to be up to date with their skills and someone good doesn't join the company
because of old tools, the cost of not upgrading probably just went up $100K
easily!!!

Calculate the cost of not upgrading as well as the cost of upgrading.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top