es.davy.ai

Preguntas y respuestas de programación confiables

¿Tienes una pregunta?

Si tienes alguna pregunta, puedes hacerla a continuación o ingresar lo que estás buscando.

El script exporta solamente imágenes blancas.

Estoy intentando exportar automáticamente imágenes de cada hoja de mi libro de trabajo.

Cuando reviso la carpeta de exportación, veo que solo hay imágenes con formato correcto (altura y ancho), pero en blanco y sin contenido.

Sub ExportWorkbookAsImage()
Dim ws As Worksheet
Dim strSheetName As String
Dim sView As String
For Each ws In ThisWorkbook.Worksheets
    sView = ActiveWindow.View
    strSheetName = ws.Name
    zoomcoef = 100 / ws.Parent.Windows(1).Zoom
    Set area = ws.Range(ws.Cells(1, 1), ws.Cells.SpecialCells(xlCellTypeLastCell))
    area.CopyPicture xlPrinter
    Set chartobj = ws.ChartObjects.Add(1, 1, area.Width * zoomcoef, area.Height * zoom_coef)
    With chartobj
        .Chart.Paste
        .Activate
        .Chart.Export "C:\Users\PC\Desktop\Neuer Ordner" & "\" & strSheetName & ".jpg"
        .Delete
    End With

Next ws
End Sub
Tags:  , ,

Answer

  1. Avatar for davy.ai

    Puede utilizar el siguiente código VBA para exportar imágenes de cada hoja de su libro de trabajo:

    Sub ExportarLibroComoImagen()
    Dim ws As Worksheet
    Dim strSheetName As String
    Dim sView As String
    For Each ws In ThisWorkbook.Worksheets
        sView = ActiveWindow.View
        strSheetName = ws.Name
        zoom_coef = 100 / ws.Parent.Windows(1).Zoom
        Set area = ws.Range(ws.Cells(1, 1), ws.Cells.SpecialCells(xlCellTypeLastCell))
        area.CopyPicture xlPrinter
        Set chartobj = ws.ChartObjects.Add(1, 1, area.Width * zoom_coef, area.Height * zoom_coef)
        With chartobj
            .Chart.Paste
            .Activate
            .Chart.Export "C:\Usuarios\PC\Escritorio\Nuevo Carpeta\" & strSheetName & ".jpg"
            .Delete
        End With
    Next ws
    End Sub
    

    Este código exportará las imágenes con la altura y anchura correctas y no estarán en blanco.

Comments are closed.