excel 如何將word的控制項結果讀入,來加以統計
- 帖子
- 14
- 主題
- 6
- 精華
- 0
- 積分
- 25
- 點名
- 0
- 作業系統
- Windows XP
- 軟體版本
- excel 2000
- 閱讀權限
- 10
- 註冊時間
- 2010-5-17
- 最後登錄
- 2023-3-24
|
excel 如何將word的控制項結果讀入,來加以統計
不是在開啟word檔後,找到控制項的TAG再讀取其值就好了嗎?(我的控制項主要是checkbox)
看似容易,但卻到不了該控制項(是用selection.goto嗎?),也找不到相關資料參考~麻煩協助一下~ |
|
|
|
|
|
|
- 帖子
- 14
- 主題
- 6
- 精華
- 0
- 積分
- 25
- 點名
- 0
- 作業系統
- Windows XP
- 軟體版本
- excel 2000
- 閱讀權限
- 10
- 註冊時間
- 2010-5-17
- 最後登錄
- 2023-3-24
|
2#
發表於 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 |
|
|
|
|
|
|