跳到主要内容

如何在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

备注:在这段代码中, Picure1 是您创建的图像名称,请根据需要进行更改。

doc插入浮动表3

4。 然后保存并关闭代码窗口,现在,当您滚动工作表并单击一个单元格时,表格图片始终保留在工作表的右上角。


箭头蓝色右气泡 使用VBA代码在Excel中插入浮动文本框

要插入浮动文本框,这也是解决此任务的VBA代码。

1。 首先,您应该从 开发商 标签,点击 开发商 > 插页 > 文本框(ActiveX控件),然后绘制文本框,然后根据需要在文本框中输入信息。 看截图:

doc插入浮动表4

2。 然后右键单击包含您要始终保持可见状态的文本框的工作表标签,然后选择 查看代码 从上下文菜单中,然后在打开的 Microsoft Visual Basic应用程序 窗口,将以下代码复制并粘贴到空白处 模块:

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中,您可以通过隐藏功能区,公式栏或状态栏来最大化工作表窗口。 Kutools for Excel's 工作区域 一键即可帮助您隐藏功能区。 立即下载并免费试用 Kutools for Excel!

最佳办公生产力工具

🤖 Kutools 人工智能助手:基于以下内容彻底改变数据分析: 智能执行   |  生成代码  |  创建自定义公式  |  分析数据并生成图表  |  调用 Kutools 函数...
热门特色: 查找、突出显示或识别重复项   |  删除空白行   |  合并列或单元格而不丢失数据   |   不使用公式进行四舍五入 ...
超级查询: 多条件VLookup    多值VLookup  |   跨多个工作表的 VLookup   |   模糊查询 ....
高级下拉列表: 快速创建下拉列表   |  依赖下拉列表   |  多选下拉列表 ....
列管理器: 添加特定数量的列  |  移动列  |  切换隐藏列的可见性状态  |  比较范围和列 ...
特色功能: 网格焦点   |  设计图   |   大方程式酒吧    工作簿和工作表管理器   |  资源库 (自动文本)   |  日期选择器   |  合并工作表   |  加密/解密单元格    按列表发送电子邮件   |  超级筛选   |   特殊过滤器 (过滤粗体/斜体/删除线...)...
前 15 个工具集12 文本 工具 (添加文本, 删除字符,...)   |   50+ 图表 类型 (甘特图,...)   |   40+ 实用 公式 (根据生日计算年龄,...)   |   19 插入 工具 (插入二维码, 从路径插入图片,...)   |   12 转化 工具 (小写金额转大写, 货币兑换,...)   |   7 合并与拆分 工具 (高级组合行, 分裂细胞,...)   |   ... 和更多

使用 Kutools for Excel 增强您的 Excel 技能,体验前所未有的效率。 Kutools for Excel 提供了 300 多种高级功能来提高生产力并节省时间。  单击此处获取您最需要的功能...

产品描述


Office Tab 为 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