2016-02-05 62 views
0

我有一個excel file.i試圖從excel中使用html提取圖像,但圖像被提取兩次。我想提取圖像並用相應的名稱保存圖像。
這是我的excel文件screenshort。 enter image description here如何從excel表中提取圖像

任何人都可以請給我一個idea.How提取使用(VBA或任何方法)從Excel文件中的圖像

+1

請分享你的代碼,你試過到目前爲止 – Siva

回答

1

下面的代碼將做到這一點(在Excel 2010中測試)。

Sub extractImgs() 
Dim shp As Shape 
Dim tempChart As String, wsName As String 
wsName = ActiveSheet.Name 
For Each shp In ActiveSheet.Shapes 
    If shp.Name Like "Picture*" Then 
     shp.Select 
     Charts.Add 
     ActiveChart.Location xlLocationAsObject, wsName 
     ActiveChart.ChartArea.Height = shp.Height 
     ActiveChart.ChartArea.Width = shp.Width 
     tempChart = Mid(ActiveChart.Name, Len(wsName) + 2, 100) 
     shp.Copy 
     ActiveChart.Paste 
     ActiveChart.Export Filename:="C:\images\" & shp.TopLeftCell.Offset(0, 1).Value & ".jpg", FilterName:="jpg" 
     ActiveSheet.Shapes(tempChart).Delete 
    End If 
Next 
End Sub 

情況下你需要初始VBA介紹:從圖像中的工作表中,右鍵單擊工作表標籤上,然後選擇「查看代碼」,然後將代碼粘貼在那裏。
確保在運行代碼之前在C:\下創建一個名爲「images」的文件夾(當光標位於代碼內時,通過點擊F5來運行它)。

+0

代碼工作,但如果在一個小區兩個圖像如何與單個ID –

+0

兩個圖像結合澄清「組合圖像」。你的意思是合併兩個圖像到一個? – EranG

+0

是的,我想合併2個圖像作爲單一IMG –