How can I populate an Excel Field with data from a Word document textbox?

Joe Patrick

New Member
Joined
May 15, 2011
Messages
44
Hi! This is the code I'm trying. I need, from Word, to open an Excel file and fill in various fields of the workbook with data from the Word document.

Can anyone help me with this?

Rich (BB code):
Sub CreateTop25Grid()
Dim objXLApplication As Excel.Application
Dim objXLWorkbook As Excel.Workbook
Set objXLApplication = CreateObject("Excel.Application")
Set objXLWorkbook = objXLApplication.Workbooks.Open("\\Fileserver\commonh\GROUP\GROUP PROCEDURES\Top 25 Contact Template.xls")
objXLApplication.Visible = True 'I'll remove this later
With ActiveWorkbook
.Range("B2").Value = ActiveDocument.TextBox1.Value & " " & Format(Date, "yyyy")
.Range("B3").Value = ActiveDocument.TextBox2.Value
.Range("B4").Value = ActiveDocument.TextBox5.Value & "-" & ActiveDocument.TextBox6.Value
End With
objXLWorkbook.SaveAs Filename:= _
        "\\Fileserver\commonh\GROUP\Top 25 Grids\" & ActiveDocument.TextBox1.Value & ".xls",  FileFormat:=xlExcel8, _
        Password:="", WriteResPassword:="", ReadOnlyRecommended:=False, _
        CreateBackup:=False
 
objXLWorkbook.Close
Set objXLWorkbook = Nothing
objXLApplication.Quit
Set objXLApplication = Nothing
End Sub

I get runtime error '438' - object does not support this property or method.

I'm sure there's a problem with having 'activeworkbook' and 'activedocument' at the same time but I don't know how to get around that.

Any help would be greatly appreciated!
 
Last edited:

Excel Facts

Back into an answer in Excel
Use Data, What-If Analysis, Goal Seek to find the correct input cell value to reach a desired result
I think the .Range references in your code expect a sheet reference in the With statment.

Change this...
Code:
With ActiveWorkbook

To something like this...
Code:
With objXLWorkbook.Sheets(1)

Where Sheets(1) is the first sheet in the workbook. You could reference a different sheet number or reference a sheet by name e.g. Sheets("Sheet1")
 
Upvote 0
OK, now I need to get the data from a word doc textbox into an excel file that is already open and I just can't seem to make it work.

Also, I need to be able to import the data back from the open excel workbook to the open word doc.

Can anyone help, please?
 
Last edited:
Upvote 0

Forum statistics

Threads
1,224,595
Messages
6,179,799
Members
452,943
Latest member
Newbie4296

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top