将Word表格链接到Excel

发布于 2024-11-30 13:25:21 字数 169 浏览 0 评论 0原文

我是一家培训机构的IT人员。很久以前,我设计了一个word表格,我们可以通过它输入要入学的人的详细信息。后来,当一批学生的数量远远超过了我们可以轻松跟踪的限制时,我设计了一个excel数据库。现在剩下的唯一问题是设计一种方法,通过它我可以复制表单字段的内容并将其链接到数据库。 希望我能得到一些东西,更简单的 VBA 也可以

I am an IT personnel in a coaching institute. I designed a form on word long ago through which we'd enter the details of the ones coming to get admission. Afterwards, when the number of students in a batch well crossed the limit where we can easily keep track of them, i designed an excel database. Now the only problem left is to devise a way through which i can copy the contents of the form field and link that to the database.
Hope i get something, an easier VBA thing would be fine as well

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

久伴你 2024-12-07 13:25:21

您可以使用 vba 和此类代码来完成此操作(从 Excel 数据库使用它来加载 Word 文档):

Sub DataFrom()

'Remember: this code requires a reference to the Word object model

Dim wdApp As New Word.Application
Dim wdDoc As Word.Document
Dim fName As String
Dim i As Long, Rw As Long

ChDir ActiveWorkbook.Path

With Application.FileDialog(msoFileDialogOpen)
  .AllowMultiSelect = False
  .Filters.Add "Word", "*.doc", 1
  .Show
  On Error GoTo Exits
  fName = .SelectedItems(1)
End With

Set wdDoc = wdApp.Documents.Open(fName)

Rw = Cells(Rows.Count, 1).End(xlUp).Row + 1
Cells(Rw, 1) = Cells(Rw - 1, 1) + 1
i = 1
For Each f In wdDoc.FormFields
  i = i + 1
  On Error Resume Next
  Cells(Rw, i) = f.Result
Next
Exits:
End Sub

You could do this with vba with this kind of code (use it from your Excel db to load Word docs):

Sub DataFrom()

'Remember: this code requires a reference to the Word object model

Dim wdApp As New Word.Application
Dim wdDoc As Word.Document
Dim fName As String
Dim i As Long, Rw As Long

ChDir ActiveWorkbook.Path

With Application.FileDialog(msoFileDialogOpen)
  .AllowMultiSelect = False
  .Filters.Add "Word", "*.doc", 1
  .Show
  On Error GoTo Exits
  fName = .SelectedItems(1)
End With

Set wdDoc = wdApp.Documents.Open(fName)

Rw = Cells(Rows.Count, 1).End(xlUp).Row + 1
Cells(Rw, 1) = Cells(Rw - 1, 1) + 1
i = 1
For Each f In wdDoc.FormFields
  i = i + 1
  On Error Resume Next
  Cells(Rw, i) = f.Result
Next
Exits:
End Sub
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文