You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何在Access窗体中替代Bound Object Frame控件展示Word文件?

Access窗体中基于文件路径展示Word内容并实现滚动的方案

方案1:Web Browser控件(最推荐)

这是最省心的方案,天然支持滚动、本地/云端文件访问,无需额外处理格式:

  • 在窗体设计视图中,添加Web Browser控件(控件工具箱→控件组中查找)
  • 加载文件路径的两种方式:
    1. 绑定字段:直接将控件的ControlSource属性设置为存储文件路径的字段
    2. VBA动态加载:在窗体的Current事件中添加代码,切换记录时自动加载对应文件:
      Private Sub Form_Current()
          If Not IsNull(Me!FilePathField) Then
              Me.WebBrowser1.Navigate Me!FilePathField
          Else
              Me.WebBrowser1.Navigate "about:blank"
          End If
      End Sub
      
  • 核心优势:支持本地路径、OneDrive/SharePoint同步路径,自带滚动条,内容自动适配控件大小,还支持文本选择、复制操作。

方案2:Rich Text Box控件(文本优先场景)

适合以纯文本或简单格式为主的Word文档,控件自带滚动功能:

  1. 先在VBA编辑器中引用Microsoft Word xx.x Object Library(工具→引用→勾选对应版本)
  2. 在窗体Current事件中添加代码,读取Word内容并导入到Rich Text Box:
    Private Sub Form_Current()
        Dim wdApp As Word.Application
        Dim wdDoc As Word.Document
        Dim tempRTFPath As String
        Dim rtfContent As String
        
        On Error GoTo Cleanup
        
        tempRTFPath = Environ("TEMP") & "\temp_doc.rtf"
        
        If IsNull(Me!FilePathField) Then
            Me.RichTextBox1.Value = ""
            Exit Sub
        End If
        
        Set wdApp = New Word.Application
        Set wdDoc = wdApp.Documents.Open(Me!FilePathField, ReadOnly:=True)
        wdDoc.SaveAs2 tempRTFPath, wdFormatRTF
        
        '读取RTF内容
        With CreateObject("Scripting.FileSystemObject")
            rtfContent = .OpenTextFile(tempRTFPath).ReadAll
        End With
        
        Me.RichTextBox1.Value = rtfContent
        
    Cleanup:
        '清理资源
        If Not wdDoc Is Nothing Then wdDoc.Close SaveChanges:=False
        If Not wdApp Is Nothing Then wdApp.Quit
        If Dir(tempRTFPath) <> "" Then Kill tempRTFPath
        Set wdDoc = Nothing
        Set wdApp = Nothing
    End Sub
    
  3. 在Rich Text Box控件的属性中,设置ScrollBars为2-垂直或3-垂直和水平,启用滚动功能。
  • 注意:复杂格式(如图片、复杂表格)可能无法完美还原。

方案3:嵌入Word ActiveX控件(完整Word功能)

需要客户端安装Word,可完整保留Word的所有功能,包括滚动、编辑:

  • 在窗体设计视图中,添加Microsoft Word Document控件(更多控件列表中查找)
  • 在窗体Current事件中添加代码加载文件:
    Private Sub Form_Current()
        If Not IsNull(Me!FilePathField) Then
            Me.WordDocument1.Object.Open Me!FilePathField, ReadOnly:=True
        Else
            '清空控件内容
            Me.WordDocument1.Object.Close SaveChanges:=False
            Me.WordDocument1.Object.Add
        End If
    End Sub
    
  • 优势:完全支持Word的格式、滚动、甚至编辑;缺点:云端文件需确保本地可访问(如同步到本地),控件资源占用较高。

内容的提问来源于stack exchange,提问作者lauro

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.10 07:05:19