Board logo

標題: excel 如何將word的控制項結果讀入,來加以統計 [打印本頁]

作者: examsuper    時間: 2014-12-31 16:19     標題: excel 如何將word的控制項結果讀入,來加以統計

不是在開啟word檔後,找到控制項的TAG再讀取其值就好了嗎?(我的控制項主要是checkbox)
看似容易,但卻到不了該控制項(是用selection.goto嗎?),也找不到相關資料參考~麻煩協助一下~
作者: examsuper    時間: 2015-1-9 16:53

小弟已有找到解決方案(如下),謝謝大家費心了~

Sub getWordItem()     
Application.ScreenUpdating = False
Dim WDAPP As New Word.Application
Dim WDDOC As Word.Document
Dim CCtrl As Word.ContentControl
Dim strFolder As String
Dim WkSht As Worksheet
Dim i As Long, j As Long
strFolder = GetFolder
If strFolder = "" Then Exit Sub
Set WkSht = ActiveSheet
i = WkSht.Cells(WkSht.Rows.Count, 1).End(xlUp).Row
strFile = Dir(strFolder & "\*.docx", vbNormal)
While strFile <> ""
      Set WDDOC = WDAPP.Documents.Open(filename:=strFolder & strFile, AddToRecentFiles:=False, Visible:=True)
     With WDDOC
          For Each CCtrl In .ContentControls
             j=j+1
             WkSht.Cells(i, j) =CCtrl.Checked
          Next
    End With
    WDDOC.Close SaveChanges:=False
    strFile = Dir()
    Wend
WDAPP.Quit
Set WDDOC = Nothing: Set WDAPP = Nothing: Set WkSht = Nothing
Application.ScreenUpdating = True


End Sub
Function GetFolder() As String      '暫不使用
Dim oFolder As Object
GetFolder = ""
Set oFolder = CreateObject("Shell.Application").BrowseForFolder(0, "Choose a folder", 0)
If (Not oFolder Is Nothing) Then GetFolder = oFolder.Items.Item.Path
Set oFolder = Nothing
End Function




歡迎光臨 麻辣家族討論版版 (http://forum.twbts.com/)