Ver Mensaje Individual
  #8 (permalink)  
Antiguo 10/04/2008, 02:56
iaras66
 
Fecha de Ingreso: octubre-2007
Mensajes: 36
Antigüedad: 17 años, 6 meses
Puntos: 0
Re: Copiar y pegar todo el texto de un Word a otro mediante visual basic 6.0

He pensado en crear una macro en el word y pasar el codigo al visual basic.
Lo que hago es copiar todo el texto, ir al final del documento, pasar a un nuevo documento y pegar ahi todo para que luego me ejecute el FOR.

Esa parte de codigo queda asi:

#################
.Selection.WholeStory
.Selection.Copy
#################

Luego introduzco los encabezados y primeros resultados....

################################################## ######
.Application.Selection.EndKey Unit:=wdStory
.Application.Selection.InsertBreak Type:=wdPageBreak
.Application.Selection.PasteAndFormat (wdPasteDefault)
################################################## #

Aqui paso al final y a una nueva hoja y pego; y apartir de ahi ejecuto el FOR.
Lo que ocurre es que me dice que el objeto hace referencia a un encabezado o pie de pagina y que el metodo o proiedad no está disponible; refiriendose a la linea para pasar a una página siguiente y la linea para pegar el texto.
Aparte de que creo q no me copiaria los siguentes resultados del Nº de cuestionario donde tiene que hacerlo.

El código queda así en global:

################################################## ###
With Documento
.Application.Documents.Open App.Path & "\Trasplante.doc"
'final del documento
.Application.Selection.EndKey wdStory
'intro
.Application.Selection.TypeParagraph
'introduccion de Encabezado
.Selection.WholeStory
.Selection.Copy
.ActiveWindow.ActivePane.View.SeekView = wdSeekCurrentPageHeader

'Para alinear el texto a la derecha

.Selection.ParagraphFormat.Alignment = wdAlignParagraphLeft
Documento.Selection.Font.Name = "Times News Roman"
Documento.Selection.Font.Size = 11


.Selection.ParagraphFormat.Alignment = wdAlignParagraphLeft
.Application.Selection.TypeText "Página" & vbNewLine

.Selection.ParagraphFormat.Alignment = wdAlignParagraphLeft
Documento.Selection.Sections(1).Headers(1).PageNum bers.Add PageNumberAlignment:= _
wdAlignPageNumberLeft, FirstPage:=True


Documento.Selection.Font.Name = "Times News Roman"
Documento.Selection.Font.Size = 11

.Application.Selection.TypeText " " & numinicio

.Application.Selection.TypeText " " + "Cuestionario"


.Application.Selection.EndKey Unit:=wdStory
.Application.Selection.InsertBreak Type:=wdPageBreak

.Application.Selection.PasteAndFormat (wdPasteDefault)
numinicioval = numinicio + 1
For i = numinicioval To numfinal


.ActiveWindow.ActivePane.View.SeekView = wdSeekCurrentPageHeader

'Para alinear el texto a la Izquierda

.Selection.ParagraphFormat.Alignment = wdAlignParagraphLeft
Documento.Selection.Font.Name = "Times News Roman"
Documento.Selection.Font.Size = 11


.Selection.ParagraphFormat.Alignment = wdAlignParagraphLeft
.Application.Selection.TypeText "Página" & vbNewLine

.Selection.ParagraphFormat.Alignment = wdAlignParagraphLeft
Documento.Selection.Sections(1).Headers(1).PageNum bers.Add PageNumberAlignment:= _
wdAlignPageNumberLeft, FirstPage:=True


Documento.Selection.Font.Name = "Times News Roman"
Documento.Selection.Font.Size = 11

.Application.Selection.TypeText " " & i

.Application.Selection.TypeText " " + "Cuestionario"

.Application.Selection.EndKey Unit:=wdStory
.Application.Selection.InsertBreak Type:=wdPageBreak
.Application.Selection.PasteAndFormat (wdPasteDefault)

Next i

'mostramos documento
.Application.Visible = True
End With
Set Documento = Nothing
Set oword = Nothing
################################################## #######################################33

Alguna idea??

Última edición por iaras66; 10/04/2008 a las 03:05