Datareport

Quisiera saber cómo puedo pasar hacer para que un datareport me lo pase a word y lo imprima desde allí.
Y otra pregunta, cómo puedo abrir un documento word (con datos) para que añada un texto??
Gracias
Respuesta
1
Checa el siguiente comentario:
Para hacerlo necesitas referenciar a WORD.
Y luego en codigo algo asi:
Para conocer un poco los comandos de word, te aconsejo que pongas a
grabar una macro, y hagas cosas, p.ejemplo escribir, cambiar fuentes,
dibujar un recuadro etc...
Luego vas a la macro, y veras el codigo de todo lo q has echo.
Dim Hay As Object 'Object
' Resume to the next line following the error.
On Error Resume Next
' Attempt to reference Word which is already running.
Set Hay = GetObject(, "Word.Application")
' If true, Word is not running.
If Hay Is Nothing Then
' Create a new instance of the Word application.
'Set Hay = New Word.Application
'late binding for hebrew
Set Hay = CreateObject("Word.Application")
' If true, MS Word 8.0 is not installed.
If Hay Is Nothing Then
MsgBox "No esta instalado Word"
Exit Sub
End If
End If
On Error GoTo ErrHandler
Hay.Visible = True
Hay.Documents.Add
If WordHide = False Then
Hay.ActiveWindow.View.Type = wdNormalView
Hay.Application.WindowState = wdWindowStateMaximize
End If
z = 1
With Hay
If HebWord = True Then 'Hebrew
z = 991
.Selection.LtrPara
z = 1
Else
If .Selection.ParagraphFormat.Alignment <> wdAlignParagraphLeft Then
.Selection.ParagraphFormat.Alignment = wdAlignParagraphLeft
End If
End If
z = 999
With .ActiveDocument.PageSetup
.LineNumbering.Active = False
.Orientation = wdOrientPortrait
.TopMargin = CentimetersToPoints(0.5)
.BottomMargin = CentimetersToPoints(1.4)
.LeftMargin = CentimetersToPoints(0.5)
.RightMargin = CentimetersToPoints(0.5)
.Gutter = CentimetersToPoints(0)
.HeaderDistance = CentimetersToPoints(1.27)
.FooterDistance = CentimetersToPoints(1.27)
.PageWidth = CentimetersToPoints(21)
.PageHeight = CentimetersToPoints(29.7)
.FirstPageTray = wdPrinterDefaultBin
.OtherPagesTray = wdPrinterDefaultBin
.SectionStart = wdSectionNewPage
.OddAndEvenPagesHeaderFooter = False
.DifferentFirstPageHeaderFooter = False
.VerticalAlignment = wdAlignVerticalTop
.SuppressEndnotes = False
.MirrorMargins = False
.TwoPagesOnOne = False
.GutterPos = wdGutterPosLeft
End With
.ActiveWindow.ActivePane.VerticalPercentScrolled = 0
.Selection.TypeParagraph
.Selection.TypeParagraph
.Selection.TypeParagraph
.Selection.TypeParagraph
.Selection.TypeParagraph
.Selection.TypeParagraph
.Selection.TypeParagraph
.Selection.TypeParagraph
.Selection.TypeParagraph
.Selection.TypeParagraph
.Selection.TypeParagraph
.Selection.TypeParagraph
.Selection.TypeText Text:="Prueba"
.Selection.HomeKey Unit:=wdLine, Extend:=wdExtend
.Selection.Font.Name = "Arial"
.Selection.Font.Size = 45
.Selection.Font.Bold = wdToggle
.Selection.EndKey Unit:=wdLine
SavingFile = (App.Path & "MyDoc.doc")
End With
'save
Hay.ActiveDocument.SaveAs FileName:=SavingFile, FileFormat:= _
wdFormatDocument, LockComments:=False, Password:="", AddToRecentFiles:= _
True, WritePassword:="", ReadOnlyRecommended:=False, EmbedTrueTypeFonts:= _
False, SaveNativePictureFormat:=False, SaveFormsData:=False, _
SaveAsAOCELetter:=False
If MsgBox("Print ?", vbYesNo) = vbYes Then
Hay.ActiveDocument.PrintOut
Sleep (3000)
Hay.Application.WindowState = wdWindowStateMinimize
MsgBox "The Report is ready, please wait while Word printing."
Hay.ActiveDocument.Close wdDoNotSaveChanges
DoEvents
Else
Hay.ActiveDocument.Close wdSaveChanges
End If
MsgBox "unloading word"
Hay.Visible = False
Hay.Application.Quit
Set Hay = Nothing
Y también verifica la siguiente liga:
http://support.microsoft.com/default.aspx?scid=kb;en-us;231726

1 respuesta más de otro experto

Respuesta
1
Ambos se solucionan con lo mismo y si el word que tienes es del xp mucho más fácil. Y quizás ni utilices el data report
'declaracion de variables
Dim Wd as New Word.Aplication
Wd.Open ("Rutadelarchivo")
Wd.Activedocument.Range.AfterInsert= Variable
Wd.Visible=True
'en Variable es el valor del texto
'o bien pon directamente un control
'como Tex1.Text
'nose en donde te insertara el texto
'asi que tendras que indicarle donde

Añade tu respuesta

Haz clic para o

Más respuestas relacionadas