跳到主要內容

如何在Excel工作表中插入浮動表或文本框?

如果您有一個表或帶有一些重要數據的文本框,即使您上下滾動工作表,也希望它們始終在工作表屏幕上可見。 這可能是一個有趣的任務,本文中,我將介紹一個快速的技巧來解決它。

使用VBA代碼在Excel中插入浮動表

使用VBA代碼在Excel中插入浮動文本框


箭頭藍色右氣泡 使用VBA代碼在Excel中插入浮動表

沒有直接的方法可以插入浮動表,因此您需要將表數據轉換為圖像,然後應用代碼來完成它,請按以下步驟操作:

1。 選擇要保持可見的數據表,然後單擊 複製 > 複製為圖片 首頁 標籤,請參見屏幕截圖:

doc插入浮動表1

2。 在彈出 複製圖片 對話框中選擇 如屏幕所示 來自 外觀 部分,然後選擇 圖片格式 部分,點擊 OK 關閉對話框,然後單擊一個單元格以輸出圖片,最後,按 按Ctrl + V 要粘貼此圖片,請參見屏幕截圖:

doc插入浮動表2

3。 將表格轉換為圖片後,然後右鍵單擊包含要始終顯示的表格圖片的工作表選項卡,然後選擇 查看代碼 從上下文菜單中,然後在打開的 適用於應用程序的Microsoft Visual Basic 窗口,將以下代碼複製並粘貼到空白模塊中:

VBA代碼:在Excel中插入浮動表:

Private Sub Worksheet_SelectionChange(ByVal Target As Range)
'Updateby Extendoffice
    Application.ScreenUpdating = False
    If Target.Cells.Count > 1 Then Exit Sub
        With ActiveSheet.Shapes("Picture1")
            .Top = ActiveWindow.VisibleRange.Top + 5
            .Left = ActiveWindow.VisibleRange.Left + ActiveWindow.VisibleRange.Width - .Width - 45
        End With
    Application.ScreenUpdating = False
End Sub

備註:在這段代碼中, 圖片1 是您創建的圖像名稱,請根據需要進行更改。

doc插入浮動表3

4。 然後保存並關閉代碼窗口,現在,當您滾動工作表並單擊一個單元格時,表格圖片始終保留在工作表的右上角。


箭頭藍色右氣泡 使用VBA代碼在Excel中插入浮動文本框

要插入浮動文本框,這也是解決此任務的VBA代碼。

1。 首先,您應該從 開發者 標籤,點擊 開發者 > 插入 > 文本框(ActiveX控件),然後繪製文本框,然後根據需要在文本框中輸入信息。 看截圖:

doc插入浮動表4

2。 然後右鍵單擊包含您要始終保持可見狀態的文本框的工作表標籤,然後選擇 查看代碼 從上下文菜單中,然後在打開的 Microsoft Visual Basic for Applications 窗口,將以下代碼複製並粘貼到空白處 模塊:

VBA代碼:在Excel中插入浮動文本框:

Private Sub Worksheet_SelectionChange(ByVal Target As Range)
'Updateby Extendoffice
    Application.ScreenUpdating = False
    With ActiveWindow.VisibleRange
        TextBox1.Top = .Top + 5
        TextBox1.Left = .Left + .Width - TextBox1.Width - 45
    End With
    Application.ScreenUpdating = True
End Sub

備註:在這段代碼中, 文字框1 是您插入的文本框名稱,請根據需要進行更改。

doc插入浮動表5

3。 然後保存並關閉代碼窗口,現在,當您將工作表滾動到任何位置時,插入的文本框始終保留在工作表的右上角。


最大化或最小化工作表窗口

為了最大化工作表窗口可以為用戶釋放更多的空間,在Excel中,您可以通過隱藏功能區,公式欄或狀態欄來最大化工作表窗口。 Excel的Kutools's 工作區域 一鍵即可幫助您隱藏功能區。 立即下載並免費試用Excel的Kutools!

最佳辦公生產力工具

🤖 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 (8)
No ratings yet. Be the first to rate!
This comment was minimized by the moderator on the site
Hola, buenos días.

Mi pregunta es cómo mantener siempre visible la imagen flotante aun cuando me desplace en distintas filas o columnas de la hoja.

Saludos y gracias por compartir tus conocimientos.
This comment was minimized by the moderator on the site
The names are the same but for some reason I am still coming across runtime error 424 object required?
This comment was minimized by the moderator on the site
Hi,
Somewhere between steps 2 and 3 on "Insert Floating Table In Excel With VBA Code" I missed how to name the picture I just copy and pasted.

Tom
This comment was minimized by the moderator on the site
Top left corner next to the box you input the formula
This comment was minimized by the moderator on the site
Same has happened to me too, how do you know the name of the picture file?
This comment was minimized by the moderator on the site
Hello, Peter,
To know the name of the picture, you just need to select the picture, and then view the name from the Name Box in the top left corner.
This comment was minimized by the moderator on the site
If I re-size the window, the picture floats too far into the middle. How do I make the picture float to the same margin from the screen no matter what size window I have?
This comment was minimized by the moderator on the site
Thank you-this solved my problem very easily!
There are no comments posted here yet
Please leave your comments in English
Posting as Guest
×
Rate this post:
0   Characters
Suggested Locations