返回列表 上一主題 發帖

[發問] VBA指定格內插入對應的圖片(程式碼討論)

[發問] VBA指定格內插入對應的圖片(程式碼討論)

各位大大們好!

目前想製作能在指定格內自動插入相對應名稱的客戶LOGO ( 插入圖片大小不能超過指定格的大小),若是找不到相對應名稱的圖片將會開啟資料夾(專門存放客戶LOGO的資料夾)
而程式撰寫部分遇到以下問題:
1.不管圖片格式如何,只要圖名與客戶名相符就能自動插入指定格中,目前寫法如下第七列 (X=Dir("")) ,不知大大們是否有更好得寫法?
2.圖片插入的地方有五個部份,表格大小都不一樣,不知是否能指定圖片大小與儲存格大小相同?
3.如何轉寫開啟指定資料夾   ((( S:archiv\LOGO
以上! 感謝各位大大!!
程式碼如下:(由於還使新手,若語法有錯再麻煩大大們糾正我一下)
  1. Sub Logo()

  2. If Sheets("Grunddefinition").Range("T5").Value <> 0 Or Sheets("Grunddefinition").Range("T5").Value <> "" Then

  3.    Dim A As String
  4.     A = Application.IfError(Application.VLookup(Sheets("Grunddefinition").Range("S5"), Sheets("Grunddefinition").Range("S5:T5"), 2, False), "")

  5.     Dim x As String
  6.     x = Dir("S:archiv\LOGO\" & A & ".png") 'Or x = Dir("S:archiv\LOGO\" & A & ".jpg")
  7.       
  8.       If x <> "" Then
  9.       
  10.          Set p = ActiveSheet.Pictures.Insert("S:archiv\LOGO\" & A & ".png") 'Or x = Dir("S:archiv\LOGO\" & A & ".jpg")
  11.          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")
  12.          
  13.    
  14.       
  15.       ElseIf x = "" Then
  16.       MsgBox "Error! Can't find the corresponding picture!"
  17.       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!"
  18.       
  19. End If

  20. ElseIf Sheets("Grunddefinition").Range("T3").Value = 0 Or Sheets("Grunddefinition").Range("T3").Value = "" Then
  21. MsgBox "Please enter the name of the customer!"
  22. Sheets("Grunddefinition").Select
  23. Rows(5).Select
  24. End If


  25. End Sub
複製代碼

        靜思自在 : 對父母要知恩,感恩、報恩。
返回列表 上一主題