Can't create word field by CommandButton_Click macro in Excel

J

Julian

As we all know, we can create a macro in word like this:

Sub Macro1()
'Using default paragraphs(1)
ActiveDocument.Paragraphs(1).Range.Text = "Date:"
ActiveDocument.Paragraphs(1).Range.Select

Selection.MoveRight

Selection.Fields.Add Range:=Selection.Range, Type:=wdFieldDate

End Sub

These codes work fine

Now we check how this work in excel(version 2003)

Private Sub CommandButton1_Click()

Dim oWord As Object

Set oWord = CreateObject("Word.Application")
oWord.Visible = True
oWord.Documents.Add


Set CurrentDoc = oWord.Documents(1)

CurrentDoc.Paragraphs(1).Range.Text = "Date:"
CurrentDoc.Paragraphs(1).Range.Select

oWord.Selection.MoveRight

oWord.Selection.Fields.Add Range:=oWord.Selection.Range,
Type:=wdFieldDate

End Sub

The last line will get runtime problem. why?
 
H

Helmut Weber

Hi Julian,
of course not, it is unknwon to Excel,

well, I think, you got it right anyway.

--

Greetings from Bavaria, Germany

Helmut Weber, MVP WordVBA

Vista Small Business, Office XP
 

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