Word

Hola, me gustaría saber cómo puedo
hacer para que el valor que tengo en una variable de tipo texto (string) me lo pase a un documento word para que pueda imprimirlo desde ahí.
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

1 respuesta más de otro experto

Respuesta
1
No se si esto te sirva
'declaracion de variables
Dim Wd as New Word.Aplication
Wd.Open ("Rutadelarchivo")
Wd.Activedocument.Conten = Variable
'esta parte coloca cualquier cantidad de texto en una hoja en blanco
Wd.Visible=True
'en Variable es el valor del texto

Añade tu respuesta

Haz clic para o

Más respuestas relacionadas