- 帖子
- 28
- 主題
- 20
- 精華
- 0
- 積分
- 70
- 點名
- 0
- 作業系統
- windows
- 軟體版本
- Office2010
- 閱讀權限
- 20
- 性別
- 女
- 註冊時間
- 2017-7-4
- 最後登錄
- 2018-8-13
|
[發問] VBA指定格內插入對應的圖片(程式碼討論)
各位大大們好!
目前想製作能在指定格內自動插入相對應名稱的客戶LOGO ( 插入圖片大小不能超過指定格的大小),若是找不到相對應名稱的圖片將會開啟資料夾(專門存放客戶LOGO的資料夾)
而程式撰寫部分遇到以下問題:
1.不管圖片格式如何,只要圖名與客戶名相符就能自動插入指定格中,目前寫法如下第七列 (X=Dir("")) ,不知大大們是否有更好得寫法?
2.圖片插入的地方有五個部份,表格大小都不一樣,不知是否能指定圖片大小與儲存格大小相同?
3.如何轉寫開啟指定資料夾 ((( S:archiv\LOGO
以上! 感謝各位大大!!
程式碼如下:(由於還使新手,若語法有錯再麻煩大大們糾正我一下)- Sub Logo()
-
- If Sheets("Grunddefinition").Range("T5").Value <> 0 Or Sheets("Grunddefinition").Range("T5").Value <> "" Then
-
- Dim A As String
- A = Application.IfError(Application.VLookup(Sheets("Grunddefinition").Range("S5"), Sheets("Grunddefinition").Range("S5:T5"), 2, False), "")
- Dim x As String
- x = Dir("S:archiv\LOGO\" & A & ".png") 'Or x = Dir("S:archiv\LOGO\" & A & ".jpg")
-
- If x <> "" Then
-
- Set p = ActiveSheet.Pictures.Insert("S:archiv\LOGO\" & A & ".png") 'Or x = Dir("S:archiv\LOGO\" & A & ".jpg")
- Set C = Sheets("Grunddefinition").Range("S1") And Sheets("Zeitablaufplan").Range("B5") And Sheets("Zeitablaufplan").Range("M5") And Sheets("Zeitablaufplan").Range("X5") And Sheets("Zeitablaufplan").Range("AI5")
-
-
-
- ElseIf x = "" Then
- MsgBox "Error! Can't find the corresponding picture!"
- MsgBox "You should check whether the picture is existing in the folder of Logo or check the name of the picture is corresponded with the name of customer!"
-
- End If
- ElseIf Sheets("Grunddefinition").Range("T3").Value = 0 Or Sheets("Grunddefinition").Range("T3").Value = "" Then
- MsgBox "Please enter the name of the customer!"
- Sheets("Grunddefinition").Select
- Rows(5).Select
- End If
- End Sub
複製代碼 |
|