• Ok heres what im trying to do, im ok with excel but not so good with word


    I have a word form and what i need to do is export the text values into an excel spreadsheet row when the user has completed the form and returned it to me


    export to be from word not an import from excel


    Any help very appreciated


    Gibbo

  • Re: word form


    Ok had a bit of a play and so far I have the code below


    Sub ExcelMacro()

    Dim ObjExcel As Excel.Application
    Dim Wkb As Excel.Workbook
    Dim WS As Excel.Worksheet
    Dim Path As String
    Dim FName As String

    Path = ThisDocument.Path
    FName = "Book1.xls"
    Set ObjExcel = New Excel.Application
    ObjExcel.Visible = True 'Add this line to make the Excel app visible
    Set Wkb = ObjExcel.Workbooks.Open(FileName:=Path & "\" & FName)
    Set WS = Wkb.Sheets("Sheet1")
    Columns("A").End(xlUp).Offset(1, 0).Select
    ActiveCell.Value = ActiveDocument.FormFields("Text1").Result
    ActiveCell.Offset(0, 1).Value = ActiveDocument.FormFields("Text2").Result
    ActiveCell.Offset(0, 2).Value = ActiveDocument.FormFields("Text3").Result
    ActiveCell.Offset(0, 3).Value = ActiveDocument.FormFields("Text4").Result
    'Wkb.Close True
    'ObjExcel.Quit

    'Set ObjExcel = Nothing
    ''Set Wkb = Nothing
    'Set WS = Nothing

    End Sub


    Is there a generic statement in word to select all user inport from the form in one go?


    I assume there must be


    Gibbo

  • Re: word form


    Hi Gibbo,


    I don't think you can output all the formfields with a single command.
    You can however loop thru all the form fields.

    [h4]Cheers
    Andy
    [/h4]

  • Re: word form


    Thanks Andy


    Managed to figure out the code i wanted as below


    Sub ExcelMacro()

    Dim ObjExcel As Excel.Application
    Dim Wkb As Excel.Workbook
    Dim WS As Excel.Worksheet
    Dim Path As String
    Dim FName As String

    Path = ThisDocument.Path
    FName = "Book1.xls"
    Set ObjExcel = New Excel.Application
    'ObjExcel.Visible = True 'Add this line to make the Excel app visible
    Set Wkb = ObjExcel.Workbooks.Open(FileName:=Path & "\" & FName)
    Set WS = Wkb.Sheets("Sheet1")

    WS.Range("A65000").End(xlUp).Offset(1, 0).Select

    For Each aField In ActiveDocument.FormFields
    If Trim(aField.Result) <> "" Then
    ActiveCell.Value = aField.Result
    ActiveCell.Offset(0, 1).Select
    End If

    Next

    Wkb.Close True
    ObjExcel.Quit

    Set ObjExcel = Nothing
    Set Wkb = Nothing
    Set WS = Nothing

    End Sub


    Next problem


    If i save this as a template how do I get word to create a command button and call the code when a new doc is opened?


    I assume it goes in the on new event but cant get any code im trying to work


    Sorry but im not familiar with Word at all


    Thanks in advance


    Gibbo

  • Re: word form


    I should add i dont want to add to the toolbars and need a command button, due to the needs of my users hence the wierd way of doing this

  • Re: word form


    Hi,


    Why would you want the code in a template?
    If users are sending you the completed word docs don't you just need the macro in a master doc. This master would then run on any docs you had open, with the exception of itself. Or could open docs in a folder and then rip the data into xl.


    Am I missing something?

    [h4]Cheers
    Andy
    [/h4]

Participate now!

Don’t have an account yet? Register yourself now and be a part of our community!