Manejar Word desde Excel

Con esta macro podrás abrir un documento word, imprimirlo, guardarlo con otro nombre, etc. Para que funcione, debes activar la referencia a Microsoft Word (desde el menú Herramientas>Referencias del editor de macros)

Sub OpenWordDoc()
‘In order to use this code you must set a reference to the
‘Word object library by doing this. In the VB Editor click
‘Tools, References. Then search for Microsoft Word n.n Object Library
‘where n.n will depend on your version of Word.

Dim wdApp As Word.Application, wdDoc As Word.Document

On Error Resume Next
Set wdApp = GetObject(, “Word.Application”)
If Err.Number <> 0 Then ‘Word isn’t already running
Set wdApp = CreateObject(“Word.Application”)
End If
On Error GoTo 0

Set wdDoc = wdApp.Documents.Open(“C:tempanyolddoc.doc”)

wdApp.Visible = True

‘Aquí puedes hacer lo que quieras: imprimir, guardar, activar…
wdDoc.PrintOut
wdDoc.SaveAs “C:temphello.doc”
wdDoc.Activate
‘etc

End Sub

.

17 Comments

  1. juan Reply
  2. LUIS MATA Reply
    • todoexcel Reply
  3. rey b Reply
    • todoexcel Reply
  4. Alberto Reply
    • todoexcel Reply
    • Daniel Reply
  5. dieta Reply
  6. carlos mario Reply
  7. JoaoM Reply
    • todoexcel Reply
  8. JoaoM Reply
  9. ahudel Reply
    • todoexcel Reply

Leave a Reply

Recibe avisos de nuevas descargas, trucos y tutoriales Excel