2015-10-22 87 views
0
Dim p As Picture 
Dim sPath As String, sFileName As String, s As String 

sPath = "C:\Users\Vivek\Downloads\SMCS\" 

'Open browser to select a picture 
Thisfile = Application.GetOpenFilename 

sFileName = Thisfile 
s = sPath & sFileName 
ActiveSheet.Pictures.insert (s) 

此代碼給了我一個錯誤1004:圖片類的插入方法失敗粘貼選擇的圖片從FSO

我想要將複製到工作表(「CONSOLE」)中的圖片粘貼到單元格C6中。

+0

您不需要將路徑添加到Application.GetOpenFilename的前面,因爲完整路徑已經存在。你基本上都是走上兩條路。 –

回答

0

檢查您的保護和權限。這似乎工作:

Sub GetAPicture() 
    Dim s As String, sh As Worksheet 
    s = "C:\TestFolder\tempxx.jpg" 
    Set sh = ActiveSheet 
    sh.Pictures.Insert (s) 
End Sub