我有一個子程序可以很好地導出從excel範圍內取出的圖像,但我面臨一個問題...即使當我設法使圖表對象是透明的,沒有邊框...導出的圖像有很多未使用的區域,我希望在導出之前進行裁剪。如何在VBA 2010上導出圖像之前裁剪圖像
Sub BtnSaveFile_Click()
Dim RgExp As Range
Dim ImageToExport As Excel.ChartObject
Const sSlash$ = "/"
Const sPicType$ = ".png"
Dim sChartName$
Dim sPath$
Dim sBook$
Set RgExp = Range("G4:N28")
RgExp.CopyPicture xlScreen, xlPicture
Set ImageToExport = ActiveSheet.ChartObjects.Add(Left:=RgExp.Left - 80, Top:=RgExp.Top - 80, Width:=RgExp.Width - 80, Height:=RgExp.Height - 80)
With ImageToExport.Chart.ChartArea.Format.Fill
.Visible = msoFalse
End With
With ImageToExport.Chart.ChartArea.Format.Line
.Visible = msoCFalse
End With
ImageToExport.Chart.Paste
Start:
sChartName = Application.InputBox("Enter A Name Of Your Choice" & vbCr & _
"There Is No Default Name Available" & vbCr & _
"The File Will Be Saved At C:\SECTIONIZER\SAVED SECTION\", "PROVIDE A NAME FOR THE VIEW", "")
If sChartName = Empty Then
MsgBox "Please Enter A File Name", , "Invalid Entry"
GoTo Start
End If
If sChartName = "False" Then
ImageToExport.Delete
Exit Sub
End If
sBook = "C:\SECTIONIZER\SAVED SECTION"
sPath = sBook & sSlash & sChartName & sPicType
ImageToExport.Chart.Export Filename:=sPath, FilterName:="PNG"
ImageToExport.Delete
ExitProc:
Application.ScreenUpdating = True
Set ImageToExport = Nothing
Set RgExp = Nothing
End Sub
我有想法尋求在圖像(左,上,右,下),每一側的第一個黑色像素裁剪,這樣的話我可以設置座標裁剪出來的空像素,但我還沒有找到這樣的代碼。
編輯:從OP的供應鏈添加圖像
從這:
要這樣:
你沒有足夠的代表附加圖片,但你可以上傳一些imgur或其他網站,並添加到問題的鏈接。我認爲看到你正在處理的事情會有所幫助。 – 2015-02-06 18:56:52
謝謝Paul!以下是實際圖像導出的鏈接:http://i.imgur.com/piQSJ45.png以下是通緝結果的鏈接:http://i.imgur.com/mmneK7e.png – 2015-02-06 19:05:09