Dowolny zakres na UserFormie

Rozwinięcie tematu z artykułu wykresnauserformie.htm.

Otóż problem był następujący: czy da się jakimś magicznym sposobem wstawić do UserForma kopię dowolnego zakresu z arkusz?

Odpowiedź jest twierdząca, a zostałą wyszperana na grupie microsoft.public.excel.programming, autor postu rondebruin (at) kabelfoon.nl.

Oto ona:

Sub make_gif_file()
    Selection.CopyPicture Appearance:=xlScreen, Format:=xlPicture

    Set ctoTheChartHolder = ActiveSheet.ChartObjects.Add(0, 0, 800, 600)

    Set chtTheChart = ctoTheChartHolder.Chart

    '   Paste the picture onto the chart and
    '   set an object variable for it
    ctoTheChartHolder.Activate
    With chtTheChart
        .ChartArea.Select
        .Paste
        Set picThePicture = .Pictures(1)
    End With

    '   Set the picture's properties...
    With picThePicture
        .Left = 0
        .Top = 0
        sglWidth = .Width + 7
        sglHeight = .Height + 7
    End With

    '   Change the size of the chart object to fit the picture
    'better
    With ctoTheChartHolder
        .Border.LineStyle = xlNone
        .Width = sglWidth
        .Height = sglHeight
    End With

    '   Which filter to use?..
    strFileExtension = "bmp"

    '   Export the chart as a graphics file
    blnRet = chtTheChart.Export(Filename:="c:\range.gif", _
                                Filtername:="gif", Interactive:=False)
    ctoTheChartHolder.Delete
End Sub