Consulting

Results 1 to 3 of 3

Thread: Import Active X fields in word doc to Excel

  1. #1
    VBAX Newbie
    Joined
    Sep 2011
    Posts
    5
    Location

    Import Active X fields in word doc to Excel

    Hey,

    So far no one has been able to help me (you fail me yet again google).

    I wanted to link you to an example on this forum but apparently my posts count is not high enough. soz

    I think the code fails because it references form fields not ADO's. Problem is I don't really know much about referencing ADO's.


    [VBA]' Add Tools > References: Microsoft Word and Microsoft Scripting Runtime

    Dim vField As TextBox
    Dim fso As Scripting.FileSystemObject
    Dim fsDir As Scripting.Folder
    Dim fsFile As Scripting.File
    Dim wdApp As Word.Application
    Dim myDoc As Word.Document
    Dim vColumn As Integer
    Dim vLastRow As Integer
    Dim i As Integer
    Dim vValue As Variant
    Dim vFileName As String
    Dim cell As Excel.Range
    Dim inPath As String, outPath As String

    inPath = "G:\6088_POG\Ent-Platform-Design\Work Package Management\References\Documentation\Process\Engagment of Service\New"
    outPath = "G:\6088_POG\Ent-Platform-Design\Work Package Management\References\Documentation\Process\Engagment of Service\Processed"
    'inPath = ThisWorkbook.Path & "\in\"
    'outPath = ThisWorkbook.Path & "\out\"


    vLastRow = ActiveSheet.UsedRange.Rows.Count + 1
    vColumn = 1

    Set fso = New Scripting.FileSystemObject
    Set fsDir = fso.GetFolder(inPath)

    Set wdApp = New Word.Application
    wdApp.Visible = True

    For Each fsFile In fsDir.Files
    wdApp.Documents.Open (fsFile)
    Set myDoc = wdApp.ActiveDocument
    For Each vField In wdApp.Documents(myDoc).FormFields
    vValue = vField.Result
    Worksheets("Rawdata").Activate 'Needed? Not needed if macro ran from it.
    Set cell = Cells(vLastRow, vColumn)

    If vField.Type = 71 Then
    Select Case vField.Name
    Case "Check1"
    vColumn = vColumn - 1
    If vField.Result = "1" Then cell.Value = "YES"
    Case "Check2"
    If vField.Result = "1" Then cell.Value = "NO"
    End Select
    Else
    cell.Value = vValue
    End If
    vColumn = vColumn + 1

    Next vField

    vColumn = 1
    vLastRow = vLastRow + 1
    vFileName = wdApp.ActiveDocument.Name
    wdApp.ActiveDocument.Close
    Name fsFile As outPath & vFileName
    Next fsFile

    wdApp.Quit[/VBA]

    Then I tried the same as the ref link I posed at the top of the page. Any thoughts or advice appreciated. I will up a copy of the doc and excel sheet if required?

    Thanks.

  2. #2
    VBAX Newbie
    Joined
    Sep 2011
    Posts
    5
    Location
    Sorry forgot to mention this code is supposed to go through a directory full of docs, import the fields from the active x text boxes into the spreadsheet.

  3. #3
    VBAX Guru Kenneth Hobs's Avatar
    Joined
    Nov 2005
    Location
    Tecumseh, OK
    Posts
    4,956
    Location

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •