|
-
Apr 22nd, 2013, 03:52 PM
#1
Thread Starter
New Member
[RESOLVED] Exporting data from Excel to Word run-time error 438
I am a novice running VBA in Word 2010. I have data in Excel 2010 that i want to export into Word automatically. The purpose is to automatically print receipts of donations that have been made to our charity and save us having to handwrite them all. The Excel database has a list of all the charitable donations that have been made. I have looked online and through the forums as far as possible and have come up with the following:
I set a Word document with my template receipt and inserted a text box named "Received" beside the donor's name.
The code for VBA is as follows:
Private Sub CommandButton1_Click()
Dim objExcel As New Excel.Application
Dim exWb As Excel.Workbook
Set exWb = objExcel.Workbooks.Open("C:\Users\user\Documents\file1.xls")
ThisDocument.Received.Caption = exWb.Sheets("Sheet1").Cells(2, 5)
exWb.Close
Set exWb = Nothing
End Sub
When I run it it returns "Run-time error 438" and when I debug highlights the row beginning ThisDocument. I have tried changing the Cells reference to Range but it returns the same error
I would be grateful for any help or to point to another post I could refer to. Being able to do this will be very useful. Thanks
Tags for this Thread
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|