Visual Basic - Ayuda Capturar Pantalla Formulario y enviar a Word

Life is soft - evento anual de software empresarial
 
Vista:
sin imagen de perfil

Ayuda Capturar Pantalla Formulario y enviar a Word

Publicado por Juan (5 intervenciones) el 13/12/2022 13:25:07
Tengo un módulo que guarda la vista de un formulario access en word y amplia la imagen hasta completar el ancho de la página en tamaño a4 horizontal.
Funciona bien la primera vez que pulsamos el botón insertado en el formulario para ejecutar el módulo. Si se intenta de nuevo da un error 462 en tiempo de ejecución ( El Equipo Servidor remoto no existe o no está disponible) y se para resaltando las lineas de código marcadas con las flechas

Sub ResizePics()
Dim shp As word.Shape
Dim ishp As word.InlineShape

If word.Selection.Type <> wdSelectionInlineShape And _ <----------
word.Selection.Type <> wdSelectionShape Then[/b][/b] <----------
Exit Sub
End If

Adjunto el código completo por si alguien puede indicarme que modificaciones tengo que hacer para evitar este error. Gracias



1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
Option Compare Database
 
Declare Sub keybd_event _
    Lib "user32" _
   (ByVal bVk As Byte, _
    ByVal bScan As Byte, _
    ByVal dwFlags As Long, _
    ByVal dwExtraInfo As Long)
 
 
Public Sub CapturarVentana()
'On Error GoTo manejar_err
    'Declaramos variables
    Dim i As Integer, x As String, Ruta As String
    Dim Wordobj As word.Application, objdoc As word.Document, objselection As word.Selection
 
    'Buscamos el último separador (\) del nombre completo de la BdD.
    i = InStrRev(CurrentDb.Name, "\")
    'Obtenemos la ruta de la carpeta en la que se va a guardar el documento
    Ruta = Left(CurrentDb.Name, i) & "Dashboard\"
 
   'keybd_event vbKeySnapshot, 1&, 0&, 0&
    keybd_event vbKeySnapshot, 0, 0, 0
 
    Set Wordobj = CreateObject("Word.Application")
 
    With Wordobj
    .Visible = True
    .Activate
    .WindowState = wdWindowStateMaximize
    End With
 
    Set objdoc = Wordobj.Documents.Open(Ruta & "DashBoard.docx")
 
    Set objselection = Wordobj.Selection
    'Paste into Word
objselection.Paste
 
   'Selecciona el objeto
 Wordobj.ActiveDocument.Shapes.SelectAll
 
 
   'Redimensiona el objeto. Requiere el módulo ResizePics()
   '-----------------------------------------------------------------------------
 
 
 Call ResizePics
   'Ruta = Ruta & Date & "\" 'Añadimos a la ruta la subcarpeta
   ' xMkDir Ruta 'Creamos la carpeta si no existía (Requiere el módulo mdlProcedimientos)
    hoy = Format(Time, "hhmmss")
 
    objdoc.SaveAs2 Ruta & "DashBoard_" & hoy & ".docx" 'Guardamos el documento
 
 
 
 
    Wordobj.Quit
    'objdoc.Close
 
    Set Wordobj = Nothing
    Set objdoc = Nothing
    Set objselection = Nothing
    MsgBox "Pantalla copiada a fichero word"
   ' Exit Sub
manejar_err:
MsgBox err.Description & err.Number, vbCritical
On Error Resume Next
Set Wordobj = Nothing
Set objdoc = Nothing
Set objselection = Nothing
 
End Sub
Sub ResizePics()
Dim shp As word.Shape
Dim ishp As word.InlineShape
 
If word.Selection.Type <> wdSelectionInlineShape And _
word.Selection.Type <> wdSelectionShape Then
Exit Sub
End If
If word.Selection.Type = wdSelectionInlineShape Then
Set ishp = word.Selection.Range.InlineShapes(1)
ishp.LockAspectRatio = False
ishp.Height = InchesToPoints(7.8)
ishp.Width = InchesToPoints(10.8)
Else
If word.Selection.Type = wdSelectionShape Then
Set shp = word.Selection.ShapeRange(1)
shp.LockAspectRatio = False
shp.Height = InchesToPoints(7.8)
shp.Width = InchesToPoints(10.8)
End If
End If
 
Set ishp = Nothing
Set shp = Nothing
End Sub
Valora esta pregunta
Me gusta: Está pregunta es útil y esta claraNo me gusta: Está pregunta no esta clara o no es útil
0
Responder