Quantcast
Channel: VBForums - Visual Basic 6 and Earlier
Viewing all articles
Browse latest Browse all 21127

Exporting data from Excel to Word run-time error 438

$
0
0
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

Viewing all articles
Browse latest Browse all 21127

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>