2013-02-01 134 views
1

我可以成功瀏覽並在所選單元格中插入圖像,並根據需要調整其大小。問題是,當我通過電子郵件發送excel文件給asscoiates時,圖像不顯示,因爲圖像文件的路徑不在他們的pc上。這裏是我使用的代碼,調用它用鍵盤快捷鍵Ctrl-I:粘貼圖像excel

Public Sub InsertAndResize() 
CellWidth = Selection.Width 
CellHeight = Selection.Height 
CellLeft = Selection.Left 
CellTop = Selection.Top 
ActiveSheet.Pictures.Insert(_ 
Application.GetOpenFilename(_ 
"JPG picture files (*.jpg),*.jpg", , "Select the picture")).Select 
Selection.ShapeRange.Width = CellWidth 
If Selection.ShapeRange.Height > CellHeight Then Selection.ShapeRange.Height = CellHeight 
With Selection 
    .Height = Selection.ShapeRange.Height - 4 
    .Width = Selection.ShapeRange.Width - 4 
    .Left = CellLeft + ((CellWidth - .Width)/2) 
    .Top = CellTop + ((CellHeight - .Height)/2) 
End With 
End Sub 

如何插入/圖片粘貼到一個細胞,消除或斷開鏈接到源文件,以便其他人可以當他們打開文件的副本時看到它?

在此先感謝您的任何建議。 史蒂夫

+0

使用'worksheet.shapes.addPicture()'方法,而不是清理從image links片'Pictures.Insert()'。將'LinktoFile'設置爲False,將'SaveWithDocument'設置爲True。 –

+0

哦,有可能重複'http:// stackoverflow.com/questions/9609631 /刪除路徑從文件名稱的圖片在vba' – bonCodigo

回答