Foros del Web » Soporte técnico » Ofimática »

Forzar la inseción de una figura en una hoja de word mediante VBA

Estas en el tema de Forzar la inseción de una figura en una hoja de word mediante VBA en el foro de Ofimática en Foros del Web. ¿Que tal? Estamos haciendo un compañero y yo una macro que para insertar una figura, prepare una hoja con marcos y titulos , y lo ...
  #1 (permalink)  
Antiguo 13/03/2009, 13:23
Avatar de caesar.l  
Fecha de Ingreso: febrero-2007
Ubicación: Aguascalientes, México
Mensajes: 1.439
Antigüedad: 17 años, 2 meses
Puntos: 91
Forzar la inseción de una figura en una hoja de word mediante VBA

¿Que tal?

Estamos haciendo un compañero y yo una macro que para insertar una figura, prepare una hoja con marcos y titulos , y lo hace bien, lo malo es que despues de cierto numero (varia de 2 a 10) genera los marcos sobre los que se pusieron anteriormente y eso estando el cursor en otra hoja, de hecho uno de los recuadros lo pone en la hoja donde quiero que se vean, los demás no. adjunto una imagen de como se ve




el codigo que hace los marcos y titulos es el siguente. el detalle es que no me genera error, sino que no hace lo que se pide
Código VBA:
Ver original
  1. Private Sub CommandButton13_Click()
  2.     Dim FigRef As String
  3.     Dim IndFRef As String
  4.     Dim TitD As String
  5.     Dim LODoc As String
  6.     Dim CF As Integer
  7.     For Each aVar In ActiveDocument.Variables
  8.     If aVar.Name = "TitDoc" Then CF = aVar.Index
  9.     Next aVar
  10.     If CF = 0 Then
  11.     MsgBox ("No existe el titulo del documento, primero debe ingresar este parametro")
  12.     Else
  13.    
  14.    
  15.     TitD = ActiveDocument.Variables("TitDoc").Value
  16.     FigRef = InputBox("ATENCION¡ Al ingresar el nombre de la figura, deje dos espacios en blanco despues ingrese el nombre de la figura: Ejemplo (Vacio 2 tabulaciones)Indicadores de contaminaciòn ")
  17.    
  18.  
  19. ActiveDocument.Shapes.AddShape(msoShapeRectangle, 464, _
  20.     640, 85, 27).Select
  21.     Selection.ShapeRange.TextFrame.TextRange.Select
  22.     Selection.Collapse
  23.     On Error GoTo Insertar:
  24.  
  25. Inicio:
  26.     Selection.InsertCaption Label:="Figura", TitleAutoText:="", Title:="", _
  27.     Position:=wdCaptionPositionBelow, ExcludeLabel:=0
  28.     GoTo Siguiente
  29. Insertar:
  30.    CaptionLabels.Add Name:="Figura"
  31.     GoTo Inicio
  32. Siguiente:
  33.     Selection.TypeText Text:=FigRef
  34.     Selection.ShapeRange.Select
  35.     Selection.Font.Size = 12
  36.     Selection.Font.Name = "Arial"
  37.     Selection.ParagraphFormat.Alignment = wdAlignParagraphCenter
  38.     Selection.Font.Color = wdColorBlack
  39.    
  40. '   EL ERROR ES AQUI, PUES EL PRIMER RECUADRO LO PONE EN LA HOJA QUE QUIERO, LOS OTROS SE PASAN AL MARCO ANTERIOR
  41.  
  42.     ActiveDocument.Shapes.AddShape(msoShapeRectangle, 50, 70, 515#, _
  43.     550).Select
  44.     Selection.ShapeRange.Fill.Visible = msoFalse
  45.     Selection.ShapeRange.Line.ForeColor.ObjectThemeColor = wdThemeColorText1
  46.     Selection.ShapeRange.Line.ForeColor.TintAndShade = 0#
  47.     Selection.ShapeRange.Line.Visible = msoTrue
  48.     Selection.ShapeRange.Line.Weight = 1#
  49.     Selection.ShapeRange.Line.Visible = msoTrue
  50.     Selection.ShapeRange.Line.Style = msoLineSingle
  51.    
  52.    
  53.     ActiveDocument.Shapes.AddShape(msoShapeRectangle, 68, _
  54.         640, 381.75, 42.75).Select
  55.     Selection.ShapeRange.TextFrame.TextRange.Select
  56.     Selection.Collapse
  57.     Selection.TypeText Text:=TitD
  58.     Selection.WholeStory
  59.     Selection.Font.Italic = wdToggle
  60.     Selection.ParagraphFormat.Alignment = wdAlignParagraphCenter
  61.     Selection.Font.Name = "Arial"
  62.     Selection.Font.Size = 10
  63.     Selection.ShapeRange.Fill.Visible = msoFalse
  64.     Selection.ShapeRange.Line.ForeColor.ObjectThemeColor = wdThemeColorText1
  65.     Selection.ShapeRange.Line.ForeColor.TintAndShade = 0#
  66.     Selection.ShapeRange.Line.Visible = msoTrue
  67.     Selection.ShapeRange.Line.Weight = 1#
  68.     Selection.ShapeRange.Line.Visible = msoTrue
  69.     Selection.ShapeRange.Line.Style = msoLineSingle
  70.    
  71.  
  72.  
  73.     IndFRef = FigRef
  74.      
  75. '    ActiveDocument.Shapes.AddShape(msoShapeRectangle, 93.6, 86.4, 421.7, _
  76. '        87.45).Select
  77. '    Selection.ShapeRange.TextFrame.TextRange.Select
  78. '    Selection.Collapse
  79. '    Selection.TypeText Text:="YHYAHYAHAYAHAYHAYAHAY"
  80.      
  81.     ActiveDocument.Shapes.AddShape(msoShapeRectangle, 68, _
  82.         690, 381.75, 21.75).Select
  83.     Selection.ShapeRange.TextFrame.TextRange.Select
  84.     Selection.Collapse
  85.     Selection.TypeText Text:=IndFRef
  86.     Selection.ParagraphFormat.Alignment = wdAlignParagraphCenter
  87.     Selection.ShapeRange.Fill.Visible = msoFalse
  88.     Selection.ShapeRange.Line.ForeColor.ObjectThemeColor = wdThemeColorText1
  89.     Selection.ShapeRange.Line.ForeColor.TintAndShade = 0#
  90.     Selection.ShapeRange.Line.Visible = msoTrue
  91.     Selection.ShapeRange.Line.Weight = 1#
  92.     Selection.ShapeRange.Line.Visible = msoTrue
  93.     Selection.ShapeRange.Line.Style = msoLineSingle
  94.     Selection.WholeStory
  95.     Selection.Font.Name = "Arial"
  96.     Selection.Font.Size = 10
  97.    
  98.     ActiveDocument.Shapes.AddShape(msoShapeRectangle, 53, 629, 509, _
  99.     97).Select
  100.     Selection.ShapeRange.Fill.Visible = msoFalse
  101.     Selection.ShapeRange.Line.ForeColor.ObjectThemeColor = wdThemeColorText1
  102.     Selection.ShapeRange.Line.ForeColor.TintAndShade = 0#
  103.     Selection.ShapeRange.Line.Visible = msoTrue
  104.     Selection.ShapeRange.Line.Weight = 1#
  105.     Selection.ShapeRange.Line.Visible = msoTrue
  106.     Selection.ShapeRange.Line.Style = msoLineSingle
  107.     Call Insertalogo
  108.    
  109.     ActiveDocument.Shapes.AddShape(msoShapeRectangle, 50, 626#, 515#, _
  110.     103#).Select
  111.     Selection.ShapeRange.Fill.Visible = msoFalse
  112.     Selection.ShapeRange.Line.ForeColor.ObjectThemeColor = wdThemeColorText1
  113.     Selection.ShapeRange.Line.ForeColor.TintAndShade = 0#
  114.     Selection.ShapeRange.Line.Visible = msoTrue
  115.     Selection.ShapeRange.Line.Weight = 1#
  116.     Selection.ShapeRange.Line.Visible = msoTrue
  117.     Selection.ShapeRange.Line.Style = msoLineSingle
  118.  
  119.    
  120.    
  121.     End If
  122.    
  123.     MACRO_PRIN.Hide
  124.     Unload MACRO_PRIN
  125.  
  126.    
  127. End Sub

Estando el "error" a partir de la linea 40. Ahora este error pasa aún cuando haya texto entre los marcos, se va a la hoja donde esta el anterior. ¿Habrá un codigo para que especifique en que hoja debe de ponerse y no solo su localizacion en la hoja?

saludos y gracias
__________________
Yo solo sé, que no sé nada...

Última edición por caesar.l; 13/03/2009 a las 18:42 Razón: quedo mal guardado el codigo
Atención: Estás leyendo un tema que no tiene actividad desde hace más de 6 MESES, te recomendamos abrir un Nuevo tema en lugar de responder al actual.
Respuesta




La zona horaria es GMT -6. Ahora son las 01:50.