Ⅰ Excel中VBA如何區分正常的圖片
需要上圖文件附到163箱mijizili
或參考下面
Excel怎樣查找圖片
Ⅱ Excel vba 不用打開或插入文件jpg,tif文件,怎麼讀取指定圖片文件的尺寸、解析度 實在是沒財富了。
Function get_file_dim(ByVal filepath As String)
'水平分辯率 161 寬度 162 垂直分辯率 163 高度 164 尺寸 31
arr = [{161,162,163,164,31}]
Dim brr()
ReDim brr(1 To UBound(arr))
Set ObiFolder = CreateObject("shell.Application").Namespace(Left(filepath, InStrRev(filepath, "\")))
For i = 1 To UBound(arr)
brr(i) = ObiFolder.getdetailsof(ObiFolder.Items.Item(Right(filepath, Len(filepath) - InStrRev(filepath, "\"))), arr(i))
Debug.Print brr(i)
Next i
get_file_dim= brr
End Function
用這個就可以了,輸入文件的完整路徑,得到一個數組,注意包含數字以外的字元,這個函數是參考以下代碼:
Sub Fileinfo()
Sheet1.Cells.ClearContents
Dim fd As FileDialog
Set fd = Application.FileDialog(msoFileDialogFolderPicker)
If fd.Show = -1 Then GetDirectory = fd.SelectedItems(1)
Dim c As Long, R As Long, i As Long
Dim FileName As Object, ObjShell As Object, ObiFolder As Object
Set ObjShell = CreateObject("shell.Application")
Set ObiFolder = ObjShell.Namespace(GetDirectory)
On Error Resume Next
c = 0
For i = 0 To 287
If i = 27 Or i = 28 Or i = 29 Or i = 31 Then
Else
c = c + 1
Cells(1, c) = ObiFolder.getdetailsof(ObiFolder.Items, i)
End If
Next i
R = 1
For Each FileName In ObiFolder.Items
c = 0
R = R + 1
For i = 0 To 287
If i = 27 Or i = 28 Or i = 29 Or i = 31 Then
Else
c = c + 1
Cells(R, c).Activate
Debug.Print ObiFolder.getdetailsof(FileName, i)
Cells(R, c) = ObiFolder.getdetailsof(FileName, i)
End If
Next i
Next FileName
ActiveSheet.ListObjects.Add xlSrcRange, [a1].CurrentRegion
Set fd = Nothing
End Sub
如果函數輸出的和我注釋的不一樣,那麼你用上面這段重新確認一下屬性的編號
Ⅲ VBA excel 查找圖片文件夾下的圖片文件,並打開。
Subpng()
Dimpn'定義文件名稱
Dimi
pn=Dir("C:UsersdxzyDesktop新建文件夾*.png")'查找第一個文件名稱
i=1
DoWhilepn<>""
Range("a"&i)=pn
'excel打開圖片文件是什麼鬼?是插入圖片嗎?
pn=Dir'查找後續文件名稱
i=i+1
Loop
EndSub
Ⅳ excel 如何用VBA識別當前復制內容是否為圖片
Excel復制時,復制對象任然處在選中狀態,藉此判斷選中內容是否是需要判斷的類型,圖片為shape對象中的一種,其類型可通過shape.type進行判斷,代碼及類型詳見下圖:
判斷選中對象是否為圖片
Ⅳ VBA 在圖片文件夾中,查找文件名包含A列文本的圖片,並復制到指定文件夾
Sub導出圖片()
'先清空目標文件夾
DimFilenameAsString
Shell"cmd/c""del/s/qC:UsersAdministratorDesktop導出的*.jpg"""'用DOS命令刪除輸出文件夾下(包含子文件夾,但不刪除子文件夾)的所有jpg文件
Application.ScreenUpdating=False
DimyAsInteger'y是行
DimFilPathAsString'這個是圖片所在的父文件夾
DimnewfilepathAsString'圖片要復制到這里
DimrngAsRange
DimsAsString
WithSheet1'選擇目標sheet
Fory=2To10'從第2行到10行
FilPath="""D:Dropbox產品jpg"&.Cells(y,1).Text&"*.jpg"""
'用XCOPY命令,復制滿足條件的文件包含子文件夾,同時也會在目標文件夾中建立相同的子文件夾
'FilePath中使用了通配符,假如產品是:A001,則可以復制"A001紅色12cm」,"A001紅色15cm」,"A001黑色12cm」,"A001白色15cm」,
Shell"cmd/c""x/s/y"&FilPath&"C:UsersAdministratorDesktop導出的"""
Next
.Cells(1,1).Select
EndWith
Application.ScreenUpdating=False
EndSub
Ⅵ Excel 如何用vba來實現對圖片的顯示
1、把圖片放在某個文件夾內。
2、用VBA程序讀取這個文件夾的文件。
3、把圖片在相應的控制項顯示。
Ⅶ 怎麼用VBA在EXCEL表格中檢索對應的產品編號的產品圖片,求指教
Private Sub Worksheet_Change(ByVal Target As Range)
Dim Myname As String
Dim Mypath As String
Dim Picname() As String
On Error Resume Next
Mypath = "C:\Users\Administrator\Pictures\圖片\"
If Target.Count = 1 And Target.Column = 1 Then
Myname = Dir(Mypath & Target.Value & "*.jpg", 0)
i = 0
For k = 0 To 10
ActiveSheet.Shapes("B" & Target.Row & k).Delete
If Err.Number = 440 Then
Exit For
End If
Next k
Do While Myname <> ""
ReDim Preserve Picname(i)
Picname(i) = Myname
i = i + 1
Myname = Dir
Loop
For j = 0 To i - 1
With ActiveSheet.Pictures.Insert(Mypath & Picname(j))
.Top = Target.Offset(0, 1).Top
.Left = Target.Offset(0, 1).Left + j * Target.Offset(0, 1).Width / (i)
.ShapeRange.LockAspectRatio = msoFalse
.Height = Target.Offset(0, 1).Height
.Width = Target.Offset(0, 1).Width / (i)
.Name = "B" & Target.Row & j
End With
Next j
End If
End Sub
在你使用的表格的CHANGE事件,添加上面代碼看看是不是符合要求。
Ⅷ excel 用 vba 圖片操作
圖片有名字的
用shapes("名字") 應該可以
如果你是手動導入,則必須手動修改名字
如果你是代碼導入的,也要設置名字
個人經驗,希望採納
Ⅸ 怎麼在EXCEL的VBA窗口控制項里按另外一個復選框內容提示顯示圖片
發給你了,你自己看下代碼,修改成你想要的加6個復選框的效果,如果有問題,再聯系我幫你修改:在A1格輸入你的存圖片的文件夾名稱(也可以不用輸在A1,直接把路徑寫在程序裡面),然後點打開窗體按鈕,窗體中復選框1中就會自動把文件夾下的所有圖片名稱加進來,然後你選擇哪個名稱就會顯示對應的圖片:
PrivateSubComboBox1_Change()
OnErrorResumeNext
'可以直接把你的文件夾路徑寫到程序里mypath後面
mypath=Trim(ThisWorkbook.Worksheets("path").Range("a1"))
IfRight(mypath,1)<>""Thenmypath=mypath&""
UserForm1.Image1.Picture=LoadPicture(mypath&ComboBox1)
EndSub
PrivateSubUserForm_Initialize()
OnErrorResumeNext
WithThisWorkbook.Worksheets("path")
'可以直接把你的文件夾路徑寫到程序里mypath後面
mypath=Trim(.Range("a1"))
IfRight(mypath,1)<>""Thenmypath=mypath&""
myfile=Dir(mypath&"*.jpg")
DoWhilemyfile<>""
UserForm1.ComboBox1.AddItemmyfile
myfile=Dir
Loop
UserForm1.ComboBox1.ListIndex=0
EndWith
EndSub
Ⅹ EXCEL VBA 顯示圖片
有兩種情況:
如果圖片顯示到整個單元格的話,可以直接在Y2單元格寫沒有這個圖片。
然後如果有圖片會把字覆蓋,看不見,沒有圖片則可以看見字,不需要代碼寫這個。
Private Sub Worksheet_BeforeDoubleClick(ByVal Target As Range, Cancel As Boolean)
If Target.Count = 1 And Target.Column = 4 Then
On Error Resume Next
Shapes("@@@@@").Delete
If Dir(ThisWorkbook.Path & "" & Target.Value & ".jpg") <> "" Then
[Y2] = ""
ActiveSheet.Shapes.AddPicture(ThisWorkbook.Path & "" & Target.Value & ".jpg", 1, 1, [Y2].Left + 5, [Y2].Top + 5, [Y2].Width - 10, [Y2].Height - 10).Name = "@@@@@"
Else
[Y2] = "沒有這個圖片"
End If
End If
End Sub