2

Estoy intentando enviar una imagen al fondo con VBA macro en Word, pero no consigo hacerlo. Intenté grabar una macro, pero tampoco funciona.

También probar la función ZOrder:

Selection.ShapeRange.ZOrder msoSendToBack

El problema al utilizarlo es que solo envía la imagen detrás si se selecciona manualmente previamente la imagen.

Este es mi código:

Sub InsertImage()
    Dim imagePath1 As String
    imagePath1 = "C:\Users\" & LCase(Environ("UserName")) & "\Desktop\SubEscritorio3\Ejercicios Matemáticas\Barra.png"
    ActiveDocument.Shapes.AddPicture FileName:=imagePath1, _
    LinkToFile:=False, _
    SaveWithDocument:=True, _
    Left:=-12, _
    Top:=439.7, _
    Anchor:=Selection.Range, _
    Width:=479, _
    Height:=21.5
    Selection.ShapeRange.ZOrder msoSendToBack

End Sub

¿Me pueden ayudar a solucionar este problema? De ante mano muchas gracias. Saludos!

2 respuestas 2

5

Encontré la forma de enviarlo al fondo con el siguiente código. Lo dejo por si a alguien le llegase a servir.

Sub InsertImage()

Dim oILS As InlineShape, oShp As Shape
Set oILS = Selection.InlineShapes.AddPicture(FileName:= _
 "C:\Users\" & LCase(Environ("UserName")) & "\Desktop\SubEscritorio3\Ejercicios Matemáticas\Barra.png", LinkToFile:=False, _
 SaveWithDocument:=True)
Set oShp = oILS.ConvertToShape
With oShp
  .WrapFormat.Type = wdWrapBehind
  .Left = -12.7
  .Top = 473
  .Height = 21.5
  .Width = 479

  
End With
End Sub
1
  • Punes no conocía yo ese método, me lo apunto, gracias. Cierra tu pregunta dándole al check aceptando tu propia respuesta, así aparecerá como pregunta respondida. Un saludo
    – el.trasgu
    el 11 jul. 2021 a las 13:20
3

Con éste código cargas una imagen como fondo del documento al iniciarse éste

Private Sub Document_Open()
    ActiveDocument.ActiveWindow.View.Type = wdWebView
    ActiveDocument.Background.Fill.UserPicture _
    PictureFile:="C:\Users\el_trasgu\Pictures\avestruz.jpg"
End Sub
1

Tu Respuesta

By clicking “Publica tu respuesta”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

¿No es la respuesta que buscas? Examina otras preguntas con la etiqueta o formula tu propia pregunta.