2016-05-04 56 views
0

我很難將圖片粘貼到我的圖表。我嘗試過各種「With TempChrt」的組合來使paste無法正常工作。 如果也許我正在圍繞我的胳膊解決問題,我願意接受建議。將範圍圖片粘貼到圖表區域以便導出不起作用

本質上,我想將具有以下特定大小,背景顏色和值的單元轉移到用戶窗體,僅用於查看目的。也抱歉,但我不能得到粗體或斜體字體工作的代碼與問題的位,但掛起的行是「.Paste」後面「With TempChrt」。對象'_chart'的方法'粘貼'失敗。

Private Sub UserForm_Initialize() 
    Dim i As Byte 
    Dim rng1 As Range, rng2 As Range 
    Dim wkshtDC As Worksheet 
    Dim TempChrt As Chart 
    Dim TempChrtNm As String 

    Set wkshtDC = Worksheets("Data & Calcs") 
    wkshtDC.Unprotect "123" 
    Set TempChrt = wkshtDC.Shapes.AddChart.Chart 
    TempChrtNm = TempChrt.Parent.Name 
    With TempChrt.Parent 
    .Width = 87.12 
    .Height = 285.12 
    .Top = wkshtDC.Range("BC28").Top 
    .Left = wkshtDC.Range("BC28").Left 
    End With 
    For i = 1 To 4 
    Set rng1 = wkshtDC.Range("BE28").Offset(0, i) 
    Set rng2 = wkshtDC.Range("BE46").Offset(0, i) 
    If i <> 1 Then 
     TempChrt.Shapes.Range(Array("chart")).Delete 
    End If 
    wkshtDC.Range(rng1.Address, rng2.Address).CopyPicture xlScreen, xlPicture 
    With TempChrt 
     .Paste 
     .Export Filename:="G:\MVOsafe\Ramp-up\misc\TempMatrix" & i & ".bmp" 
    End With 
    Me.Controls("Frame" & i).Picture = LoadPicture("G:\MVOsafe\Ramp-up\misc\TempMatrix" & i & ".bmp") 
    Next i 
    TempChrt.Parent.Delete 
    wkshtDC.Protect "123" 

End Sub 

回答

0

明白了...

With TempChrt 

改爲

wkshtDC.Range(rng1.Address, rng2.Address).CopyPicture xlScreen, xlPicture 
    wkshtDC.ChartObjects(TempChrtNm).Activate 
    With ActiveChart 
     .Paste 
     .Export Filename:="G:\MVOsafe\Ramp-up\misc\TempMatrix" & i & ".bmp" 
    End With 

其中

TempChrtNm = TempChrt.Parent.Name 
相關問題