How to convert form data from Word to Excel

How to convert form data from Word to Excel


Related posts

  • Instructions to convert excel content to Word 2016
  • The easiest way to convert Excel to Word 2003
  • How to convert Word to PowerPoint 2007, Copy data from Docx to Ppt 2007
  • How to convert rows to columns in Excel
  • How to convert text to Excel date


Convert data from Word to Excel, you already know how to do this. This is quite a useful trick to help you convert data from Word to Excel for different purposes.

How to convert form data from Word to Excel

In the article Taimienphi guide you will take an example with the result sheet with 2 fields SchoolName and Address. Saved at the E: Examples Gradebook.xlsx path

Step 1: Add tab Developer for Word. Choose Office button Word options

Step 2: Select a tab Popular → tick select Show Developer tab in the Ribbon OK.

Step 3: Select a tab Developer Legacy Tools Text Form Field

Appeared on the Word page is now the tool Text Form Field.

Step 4: Double-click on tools Text Form Field. Type txtSchooName into the box BookmarkOK.

Step 5: Create one more Text Form Field tool for the Address field.

Step 6: Type txtAddress into the box Bookmark OK.

Step 7: Press the key combination Alt + F11 to start VBE (Visual Basic Editor).

Step 8: To enter Insert Module

Step 9: Copy the following code into the module window. Then save and return to Word.

Sub TransferToExcel ()

‘Transfer a single record from the form fields to an Excel workbook.

Dim doc As Document

Dim strSchoolName As String

Dim strPhone As String

Dim strSQL As String

Dim cnn As ADODB.Connection

‘Get data.

Set doc = ThisDocument

On Error GoTo ErrHandler

strSchoolName = Chr (39) & doc.FormFields (“txtSchoolName”). Result & Chr (39)

strPhone = Chr (39) & doc.FormFields (“txtPhone”). Result & Chr (39)

‘Define sql string used to insert each record in the destination workbook.

‘Don’t omit the $ in the sheet identifier.

strSQL = “INSERT INTO [PhoneList$]”_

& “(SchoolName, Phone)” _

& “VALUES (” _

& strSchoolName & “,” _

& strPhone _

& “)”

Debug.Print strSQL

‘Define connection string and open connection to destination workbook file.

Set cnn = New ADODB.Connection

With cnn

.Provider = “Microsoft.ACE.OLEDB.12.0”

.ConnectionString = “Data Source = E: Examples Gradebook.xlsx;” & _

– “Extended Properties = Excel 8.0;”

.Open

Transfer data

Execute strSQL

End With

Set doc = Nothing

Set cnn = Nothing

Exit Sub

ErrHandler:

MsgBox Err.Number & “:” & Err.Description, _

-vbOKOnly, “Error”

On Error GoTo 0

On Error Resume Next

cnn.Close

Set doc = Nothing

Set cnn = Nothing

End Sub

Step 10: Double-click Text Form Field school Address. Choose TransferToExcel in the box Exit OK.

Now, when you press the Tab key on your keyboard, the Address field will copy data from the SchoolName and Address fields to the Gradebook.xlsx file with the path E: Examples Gradebook.xlsx. If the excel file and the path to your file are different, please edit the code according to the file name and path to your excel file.

Knowing your data is key to converting each new record without serious problems. The example code contains the skills you will need to get started. You need advanced techniques to accommodate data and a number of other requirements.

https://thuthuat.taimienphi.vn/chuyen-form-du-lieu-tu-word-sang-excel-1424n.aspx
Thus, ElectrodealPro finished guiding you how to convert data (Form) from word to excel, if you want to convert it back, you can do it by way. convert excel to word, copy and insert excel into word.

.

Related Posts