參考資料:https://dotblogs.com.tw/peterlion_tw/2016/02/20/102934
今天看老婆大人,一直再做重覆的一件事情,選取截圖–>另存新檔–>改檔名
上網查了一下,果然可以使用VBA處理
將選取的第一個儲存格當作檔名,選取完後,另存成JPG圖檔
Sub saveaspicture()
''' Selection Range you want to export to file
Dim rgExp As Range
Set rgExp = Selection
'MsgBox "A" & rgExp.Row
'Range("B3").Value = 2
'MsgBox Range("A" & rgExp.Row).Value
''' Copy range as picture onto Clipboard
rgExp.CopyPicture Appearance:=xlScreen, Format:=xlPrinter
''' Create an empty chart with exact size of range copied
With ActiveSheet.ChartObjects.Add(Left:=rgExp.Left, Top:=rgExp.Top, _
Width:=rgExp.Width, Height:=rgExp.Height)
.Name = "myChart"
.Activate
End With
''' Paste into chart area, export to file, delete chart.
ActiveChart.Paste
ActiveSheet.ChartObjects("myChart").Chart.Export ThisWorkbook.Path & "\" & Range("A" & rgExp.Row).Value & ".jpg"
ActiveSheet.ChartObjects("myChart").Delete
End Sub
沒有留言:
張貼留言