开发者

Link word form to excel

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


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
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜