How to write in Word w/o Reference

  • Thread starter Gérard Ducouret
  • Start date
G

Gérard Ducouret

Hello,
I need to write data and symbols in a Word document, without any Reference
to Microsoft Word 11.0 because another application is disturbed by such a
reference. So I tried the folowing macro, but the wdAlignParagraphCenter
and .Color = wdColorRed don't work until I reset the reference.
What can I do ?
Thanks for your help.

Gérard

Public Sub CALL_WORD()
Dim wrdApp As Object
Dim wrdDoc As Object
Dim MyTable4 As Object

Set wrdApp = CreateObject("Word.Application")
wrdApp.Visible = True

Set wrdDoc = wrdApp.Documents.Open(FileName:="D:\Mes
documents\Pilotage\Fiche Pilotage 3 WPs V2.doc")

Set MyTable4 = wrdDoc.Tables(4)
MyTable4.Cell(Row:=4, Column:=11).Range.Text = Chr(236) 'Chr(236)
'Flèche ascendante
MyTable4.Cell(Row:=4, Column:=11).Range.Select
wrdDoc.Application.Selection.ParagraphFormat.Alignment =
wdAlignParagraphCenter 'Doesn't work!!!

With wrdDoc.Application.Selection.Font
.Name = "Wingdings"
.Size = 16
.Bold = True
.Color = wdColorRed ''Doesn't work!!!
End With

wrdDoc.Close SaveChanges:=True
wrdApp.Quit
Set wrdApp = Nothing
Set wrdDoc = Nothing

End Sub
 
C

Chris Marlow

Hi,

I've just answered your related post before reading this one.

On this 'wdAlignParagraphCenter' is only known when the reference is set.

wdAlignParagraphCenter will be part of an enumeration & therefore have a
numeric representation (just checked, it is 1). You would need to either
validate (or assume - as it probably is) that it was the same in all versions
& use the number, or, better set up your own enumeration within your code
(public type) with scope as required.

Regards,

Chris.
 
T

Tom Ogilvy

these represent constants that are defined in the Word object library. When
you late bind, these constants are not defined and are just
undefined/uninitialized variables and result in a value of zero. The
solution is to use there defined value instead of the constant.

instead of
.Color = wdColorRed
you would do


? wdred
6

.color = 6


? wdAlignParagraphCenter
1

so

wrdDoc.Application.Selection.ParagraphFormat.Alignment = 1

as examples.

to get the values,

? wdAlignParagraphCenter
1

is from the immediate window of excel after creating a reference to word.
 
T

Tom Ogilvy

Using the hard coded number should be robust for any version that supports
that object/property/method
 
G

Gérard Ducouret

Thanks a lot Tom !

Gérard

Tom Ogilvy said:
these represent constants that are defined in the Word object library. When
you late bind, these constants are not defined and are just
undefined/uninitialized variables and result in a value of zero. The
solution is to use there defined value instead of the constant.

instead of
.Color = wdColorRed
you would do


? wdred
6

.color = 6


? wdAlignParagraphCenter
1

so

wrdDoc.Application.Selection.ParagraphFormat.Alignment = 1

as examples.

to get the values,

? wdAlignParagraphCenter
1

is from the immediate window of excel after creating a reference to word.
 

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