跳到主要內容

如何在Excel中快速調整多個單元格的大小以適合圖片?

眾所周知,Microsoft Excel支持自動調整單元格的行高和列寬的大小以適合填充的內容,例如長文本字符串。 但是,“自動調整行高”命令和“自動調整列寬”命令對圖片無效,因為插入的圖片未駐留在特定的單元格中。

使用VBA調整單元格大小以適合圖片

使用Kutools for Excel調整圖片大小以適合單元格 好主意3


使用VBA調整單元格大小以適合圖片

假設工作表中有兩張大圖片,請參見下面的屏幕截圖。 有人可能想要調整單元格的大小以適合單元格上方的圖片。 但是如何實現呢?

doc調整單元格以適合picture1

當然,您可以自動調整每個單元格的大小以適合其上方的圖片。 然而,對於許多圖片而言,這可能是乏味且耗時的。 實際上,我們可以應用VB宏來調整所有單元格的大小以適合其上方的圖片。 您可以按照以下步驟進行操作:

步驟1:按住 ALT + F11 鍵,然後打開 Microsoft Visual Basic for Applications 窗口。

步驟2:點擊 插入 > 模塊,然後將以下宏粘貼到“模塊窗口”中。

VBA:調整多個單元格的大小以適合其圖片。

Sub ResizePictureCells()
For Each Picture In ActiveSheet.DrawingObjects
PictureTop = Picture.Top
PictureLeft = Picture.Left
PictureHeight = Picture.Height
PictureWidth = Picture.Width
For N = 2 To 256
If Columns(N).Left > PictureLeft Then
PictureColumn = N - 1
Exit For
End If
Next N
For N = 2 To 65536
If Rows(N).Top > PictureTop Then
PictureRow = N - 1
Exit For
End If
Next N
Rows(PictureRow).RowHeight = PictureHeight
Columns(PictureColumn).ColumnWidth = PictureWidth * (54.29 / 288)
Picture.Top = Cells(PictureRow, PictureColumn).Top
Picture.Left = Cells(PictureRow, PictureColumn).Left
Next Picture
End Sub

步驟3:按下 F5 運行此宏的鍵。

現在在當前工作表中,如果有圖片,則在下面的單元格中將調整圖片大小以適合其上方的圖片。 請參見以下屏幕截圖:

doc調整單元格以適合picture2


使用Kutools for Excel調整圖片大小以適合單元格

如果您按照下面的屏幕截圖所示調整了單元格的大小,然後要導入圖片並調整其大小以適合單元格的大小,那麼如何快速完成呢? 在這種情況下, Excel的Kutools's 導入Pictrue 實用程序可以幫助您輕鬆地完成這項工作。
doc調整圖片大小適合單元格1

Excel的Kutools, 與以上 120 方便的功能,使您的工作更加輕鬆。 

安裝後 Kutools for Excel,請執行以下操作:(立即免費下載Kutools for Excel!)

1。 點擊 企業 > 進出口 > 導入圖片。 看截圖:
doc調整圖片大小適合單元格2

2.在彈出 導入圖片 對話框中,您可以先在 進口訂單 部分,然後單擊 加入 按鈕從文件夾或文件中逐張添加圖片,然後您可以在 圖片 部分。 看截圖:
doc調整圖片大小適合單元格3

3。 然後點擊 進口 顯示按鈕 導入圖片尺寸 對話框,然後檢查 匹配的細胞大小 選項。 看截圖:
doc調整圖片大小適合單元格4

4。 點擊 OK > 進口 顯示對話框以選擇要導入圖片的單元格。 看截圖:
doc調整圖片大小適合單元格5

5。 點擊 OK,現在所有pirtcures都導入到單元中,並調整其大小以適合單元。
doc調整圖片大小適合單元格6


相關文章:
如何在Excel中的單元格中插入多張圖片?

最佳辦公生產力工具

🤖 Kutools 人工智慧助手:基於以下內容徹底改變數據分析: 智慧執行   |  生成代碼  |  建立自訂公式  |  分析數據並產生圖表  |  呼叫 Kutools 函數...
熱門特色: 尋找、突出顯示或識別重複項   |  刪除空白行   |  合併列或儲存格而不遺失數據   |   沒有公式的回合 ...
超級查詢: 多條件VLookup    多值VLookup  |   跨多個工作表的 VLookup   |   模糊查詢 ....
高級下拉列表: 快速建立下拉列表   |  依賴下拉列表   |  多選下拉列表 ....
欄目經理: 新增特定數量的列  |  移動列  |  切換隱藏列的可見性狀態  |  比較範圍和列 ...
特色功能: 網格焦點   |  設計圖   |   大方程式酒吧    工作簿和工作表管理器   |  資源庫 (自動文字)   |  日期選擇器   |  合併工作表   |  加密/解密單元格    按清單發送電子郵件   |  超級濾鏡   |   特殊過濾器 (過濾粗體/斜體/刪除線...)...
前 15 個工具集12 文本 工具 (添加文本, 刪除字符,...)   |   50+ 圖表 類型 (甘特圖,...)   |   40+ 實用 公式 (根據生日計算年齡,...)   |   19 插入 工具 (插入二維碼, 從路徑插入圖片,...)   |   12 轉化 工具 (數字到單詞, 貨幣兌換,...)   |   7 合併與拆分 工具 (高級合併行, 分裂細胞,...)   |   ... 和更多

使用 Kutools for Excel 增強您的 Excel 技能,體驗前所未有的效率。 Kutools for Excel 提供了 300 多種進階功能來提高生產力並節省時間。  點擊此處獲取您最需要的功能...

產品描述


Office選項卡為Office帶來了選項卡式界面,使您的工作更加輕鬆

  • 在Word,Excel,PowerPoint中啟用選項卡式編輯和閱讀,發布者,Access,Visio和Project。
  • 在同一窗口的新選項卡中而不是在新窗口中打開並創建多個文檔。
  • 將您的工作效率提高 50%,每天為您減少數百次鼠標點擊!
Comments (4)
No ratings yet. Be the first to rate!
This comment was minimized by the moderator on the site
How did you get come up with the formula (Columns(PictureColumn).ColumnWidth = PictureWidth * (54.29 / 288))? It's close but there is still a gap to the right as shown in your screenshot.
This comment was minimized by the moderator on the site
Great and all, but i already had pictures in cells and by using the first option it obliterated like 99% of all photos already present. None were spared except for one photo which was resized beautifully except that the width of the photo was a bit thin.
This comment was minimized by the moderator on the site
Hello Thank you for the macro. I cannot get to work in my computer though. I use Excel 2011 for Mac Any ideas? Thanks
This comment was minimized by the moderator on the site
Hi, great macro - small correction with greater OR EQUAL in the 16 row If Rows(N).Top >= PictureTop Then
There are no comments posted here yet
Please leave your comments in English
Posting as Guest
×
Rate this post:
0   Characters
Suggested Locations