Ver Mensaje Individual
  #1 (permalink)  
Antiguo 31/03/2008, 04:08
iaras66
 
Fecha de Ingreso: octubre-2007
Mensajes: 36
Antigüedad: 16 años, 6 meses
Puntos: 0
Insertar datos en Word mediante VB 6.0

Hola!!! la parte del código que me abre el Word deseado me va bien pero a la hora de insertar los datos ahí no... me da un error de "Error 438, el objeto no admite esta propiedad o metodo (refiriendose a la variable oApp a la hora de asignarle la ruta del documento)" en la siguiente parte de código:

Private Sub Command1_Click()
Dim WordObj As New Word.Application
Dim paginas As Integer
Dim ruta As String
Dim oApp As Word.Document
Dim Doc As Word.Document

'Start a new document in Word
Me.CommonDialog1.ShowOpen
ruta = Me.CommonDialog1.FileName
Set oApp = WordObj.Documents.Open(ruta)
Set Doc = oApp.Documents.Add

Luego el código seguiría así:


With Doc.MailMerge

'Insert the mail merge fields temporarily so that
'you can use the range containing the merge fields as a layout
'for your labels -- to use this as a layout, you can add it
'as an AutoText entry.
With .Fields
.Application.Selection.TypeText "Nº Cuestionario"
oApp.Selection.TypeParagraph
.Add oApp.Selection.Range, "numinicio"
oApp.Selection.TypeParagraph
.Application.Selection.TypeText "Nº Cuestionario2"
oApp.Selection.TypeParagraph
.Add oApp.Selection.Range, "numfinal"
oApp.Selection.TypeParagraph
.Application.Selection.TypeText "Nº Página"
oApp.Selection.TypeParagraph
.Add oApp.Selection.Range, "numpagina"
oApp.Selection.TypeParagraph

End With
Dim oAutoText As Word.AutoTextEntry
Set oAutoText = oApp.NormalTemplate.AutoTextEntries.Add("MyLabelLa yout", oDoc.Content)
oDoc.Content.Delete 'Merge fields in document no longer needed now
'that the AutoText entry for the label layout
'has been added so delete it.

'Set up the mail merge type as mailing labels and use
'a tab-delimited text file as the data source.
.MainDocumentType = wdMailingLabels
.OpenDataSource Name:="C:\Proyecto\Data.accdb" 'Specify your data source here

'Create the new document for the labels using the AutoText entry
'you added -- 5160 is the label number to use for this sample.
'You can specify the label number you want to use for the output
'in the Name argument.
oApp.MailingLabel.CreateNewDocument Name:="5160", Address:="", _
AutoText:="MyLabelLayout", LaserTray:=wdPrinterManualFeed

'Execute the mail merge to generate the labels.
.Destination = wdSendToNewDocument
.Execute

'Delete the AutoText entry you added
oAutoText.Delete

End With

'Close the original document and make Word visible so that

'the mail merge results are displayed
oDoc.Close False
oApp.Visible = True

'Prevent save to Normal template when user exits Word
oApp.NormalTemplate.Saved = True

Como podría hacer para meter los datos en el documento elegido????