Excel插入圖片

1在單元格批注中插入圖片

Sub 批注插圖()

? ? Dim arr As Object, FilPath$, rng As Range, Nrow%, address_picture$

? ? Application.Calculation = xlManual

? ? address_picture = InputBox("默認(rèn)為桌面文件夾圖片", "請(qǐng)輸入圖片路徑", "輸入路徑")

? ? With Sheets("圖片")

? ? ? ? .Cells.ClearComments

? ? ? ? Nrow = .[a65536].End(3).Row

? ? ? ? If Nrow = 2 Then Exit Sub

? ? ? ? Set arr = .Range("a2:a" & Nrow)

? ? ? ? For Each rng In arr

? ? ? ? ? ? FilPath = address_picture & rng.Text & ".jpg"

? ? ? ? ? ? If Dir(FilPath) <> "" Then

? ? ? ? ? ? ? ? With rng.AddComment

? ? ? ? ? ? ? ? ? ? .Visible = True

? ? ? ? ? ? ? ? ? ? .Text Text:=""

? ? ? ? ? ? ? ? ? ? .Shape.Select True

? ? ? ? ? ? ? ? ? ? Selection.ShapeRange.Fill.UserPicture FilPath

? ? ? ? ? ? ? ? ? ? .Shape.Width = 150

? ? ? ? ? ? ? ? ? ? .Shape.Height = 150

? ? ? ? ? ? ? ? ? ? .Visible = False

? ? ? ? ? ? ? ? End With

? ? ? ? ? ? End If

? ? ? ? Next

? ? End With

? ? Set arr = Nothing

? ? Application.Calculation = xlAutomatic

End Sub

2 插入鏈接圖片

Sub 插入圖片()

? ? Application.ScreenUpdating = False

? ? With ActiveSheet

? ? ? ? For i = 1 To 21

? ? ? ? ? ? FilePath = "\\Zww\GX\下單圖片\" & .Cells(i, 1).text & ".jpg"

? ? ? ? ? ? If Dir(FilePath) <> "" Then

? ? ? ? ? ? ? ? Set rng = .Cells(i, 2)

? ? ? ? ? ? ? ? Set Insert_Pic = .Pictures.Insert(FilePath)

? ? ? ? ? ? ? ? With Insert_Pic

? ? ? ? ? ? ? ? ? ? .Placement = xlMoveAndSize

? ? ? ? ? ? ? ? ? ? .ShapeRange.LockAspectRatio = msoFalse

? ? ? ? ? ? ? ? ? ? .Top = rng.Top+3

? ? ? ? ? ? ? ? ? ? .Left = rng.Left+3

? ? ? ? ? ? ? ? ? ? .Height = rng.Height-6

? ? ? ? ? ? ? ? ? ? .Width = rng.Width-6

? ? ? ? ? ? ? ? End With

? ? ? ? ? End If

? ? ? ? Next

? ? End With

? ? Application.ScreenUpdating = True

End Sub

2在單元格中插入圖片

Sub 單元格圖片()

? ? Application.ScreenUpdating = False

? ? Dim n%, i%, address_picture$, FilePath$

? ? Dim pictures As Object

? ? n = [a65536].End(3).Row

? ? address_picture = InputBox("默認(rèn)為桌面文件夾圖片", "請(qǐng)輸入圖片路徑", "輸入路徑")

? ? For i = 2 To n

? ? ? ? FilePath = Dir(address_picture & Cells(i, 1) & ".*g")

? ? ? ? If Cells(i, 1) <> "" Then

? ? ? ? ? ? If Len(FilePath) > 0 Then

? ? ? ? ? ? ? ? With ActiveSheet.Cells(i, 2)

? ? ? ? ? ? ? ? ? ? ActiveSheet.Shapes.AddPicture address_picture & FilePath, True, True, .Left, .Top, .Width, .Height

? ? ? ? ? ? ? ? End With

? ? ? ? ? ? End If

? ? ? ? End If

? ? Next i

? ? Application.ScreenUpdating = True

End Sub

3點(diǎn)擊單元格顯示圖片

Private Sub Worksheet_SelectionChange(ByVal Target As Range)

? ? Dim FilePath$

? ? FilePath = "\\192.168.6.6\pic\" & Cells(Target.Row, 1) & ".JPG"

? ? If Target.Column = 1 Then

? ? ? ? If Len(Dir(FilePath)) <> 0 Then

? ? ? ? ? ? With Image1

? ? ? ? ? ? ? ? .Picture = LoadPicture(FilePath)

? ? ? ? ? ? ? ? .Visible = True

? ? ? ? ? ? End With

? ? ? ? End If

? ? End If

4將批注的圖片顯示在單元格中

Sub 提取圖片()

? ? Dim Nrow&, i&, Pic_Width&, Pic_Height&, Com_Width&, Com_Height&, t!

? ? Application.ScreenUpdating = False

? ? Application.DisplayCommentIndicator = xlCommentAndIndicator

? ? On Error Resume Next

? ? With ActiveSheet

? ? ? ? Nrow = .[a65536].End(3).Row

? ? ? ? For i = 2 To Nrow

? ? ? ? ? ? If Not (.Range("a" & i).Comment Is Nothing) Then

? ? ? ? ? ? ? ? With .Range("a" & i).Comment

? ? ? ? ? ? ? ? ? ? Pic_Width = Range("h" & i).Width

? ? ? ? ? ? ? ? ? ? Pic_Height = Range("h" & i).Height

? ? ? ? ? ? ? ? ? ? With .Shape

? ? ? ? ? ? ? ? ? ? ? ? Com_Width = .Width

? ? ? ? ? ? ? ? ? ? ? ? Com_Height = .Height

? ? ? ? ? ? ? ? ? ? ? ? .ScaleWidth Pic_Width / Com_Width, msoFalse, msoScaleFromTopLeft

? ? ? ? ? ? ? ? ? ? ? ? .ScaleHeight Pic_Height / Com_Height, msoFalse, msoScaleFromTopLeft

? ? ? ? ? ? ? ? ? ? ? ? .CopyPicture xlScreen, xlPicture

? ? ? ? ? ? ? ? ? ? End With

? ? ? ? ? ? ? ? End With

? ? ? ? ? ? ? ? t = Timer

? ? ? ? ? ? ? ? While Timer < t + 0.01

? ? ? ? ? ? ? ? ? ? DoEvents

? ? ? ? ? ? ? ? Wend

? ? ? ? ? ? ? ? .Paste .Range("h" & i)

? ? ? ? ? ? ? ? With .Range("a" & i).Comment

? ? ? ? ? ? ? ? ? ? With .Shape

? ? ? ? ? ? ? ? ? ? ? ? .ScaleWidth Com_Width / Pic_Width, msoFalse, msoScaleFromTopLeft

? ? ? ? ? ? ? ? ? ? ? ? .ScaleHeight Com_Height / Pic_Height, msoFalse, msoScaleFromTopLeft

? ? ? ? ? ? ? ? ? ? End With

? ? ? ? ? ? ? ? End With

? ? ? ? ? ? End If

? ? ? ? Next i

? ? End With

? ? Application.ScreenUpdating = True

? ? Application.DisplayCommentIndicator = xlCommentIndicatorOnly

End Sub

5點(diǎn)擊公式打開(kāi)圖片

=HYPERLINK("\\192.168.6.6\pic\"&A2&".jpg",A2)

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請(qǐng)結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡(jiǎn)書(shū)系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

  • rljs by sennchi Timeline of History Part One The Cognitiv...
    sennchi閱讀 7,817評(píng)論 0 10
  • 管理的精妙在于"方圓合一,方為其中" 在《行成于思》一書(shū)中,筆者曾形象地寫(xiě)道:"管理是什么?像一個(gè)方塊,似一個(gè)圓弧...
    JamesT閱讀 266評(píng)論 0 0
  • 閑來(lái)無(wú)事,看了看簡(jiǎn)書(shū)首頁(yè)的文章,想學(xué)習(xí)各位大牛大神的“經(jīng)驗(yàn)之談”,看到一篇叫教人寫(xiě)作的,呵呵噠了一下,突然來(lái)了點(diǎn)靈...
    馬拉揚(yáng)閱讀 390評(píng)論 12 3
  • 最近剛剛讀完《從零開(kāi)始做運(yùn)營(yíng)》對(duì)于書(shū)中總結(jié)的框架知識(shí)點(diǎn),非常受用。作為一個(gè)工作多年的運(yùn)營(yíng)人就應(yīng)該對(duì)于運(yùn)營(yíng)的架構(gòu)有一...
    慕七七_(dá)閱讀 2,465評(píng)論 0 0

友情鏈接更多精彩內(nèi)容