View Single Post
  #8   Report Post  
Posted to microsoft.public.excel.programming,microsoft.public.word.vba.beginners
Doug Robbins - Word MVP[_2_] Doug Robbins - Word MVP[_2_] is offline
external usenet poster
 
Posts: 3
Default passing variables from excel to word

HI Mike,

How about if you include

oDoc.Save

before setting things to nothing.

Please post any further questions or followup to the newsgroups for the
benefit of others who may be interested. Unsolicited questions forwarded
directly to me will only be answered on a consulting basis.

Hope this helps
Doug Robbins - Word MVP
"Mike NG" wrote in message
...
On Sat, 19 Jul 2003 at 20:22:32, Doug Robbins - Word MVP (Doug Robbins -
Word MVP ) wrote:
In the Word VBA code, you can use oDoc.Variables('Product") or
oDoc.Variables('Product").Value (though the value is not really necessary
because it is the default property of a Variable. Having does maybe make
the code a bit easier to understand )

The variables do not have to appear anywhere in the document if you don't
want them to, so you can leave the value in them. If you do want to

display
the value of the variable in the document, you do so by use of a {
DOCVARIABLE "Product" } field.

I seem to be having some sort of synchronisation problem. This is my
excel code

Sub OpenWord()

Dim oDoc As Word.Document
Dim oWord As Word.Application


'See if word's already running
On Error Resume Next
Set oWord = GetObject(, "Word.Application")
If Err Then
'No, so start a new word session
Set oWord = New Word.Application
Err.Clear
End If

oWord.Visible = True
oWord.Activate
Set oDoc = oWord.Documents.Open(ThisWorkbook.Path & "\Envelope.doc")
oDoc.Variables("Product") = "HELLO WORLD"
Set oWord = Nothing
Set oDoc = Nothing

End Sub



This is a simplified version of my word document open event

Private Sub Document_Open()

MsgBox "" & ThisDocument.Variables("Product") & "<<"

End Sub


However, when word opens, it tells me the object has been deleted
--
Mike