Writing to work doc instead of Debug.print

B

Barb Reinhardt

I'd like to write all of my "debug.print" lines to a Word doc. I've done
Excel programming before but nothing in Word, so need some assistance.

This is what I have that needs to be converted.

If wdDoc Is Nothing Then
Set wdDoc = Documents.Add
End If

'Want to copy this to the wdDoc

Debug.Print
Debug.Print oDoc.Name
For i = 1 To 26
Debug.Print i, DataArray(i, 1), DataArray(i, 2)
Next i

Thanks,
Barb Reinhardt
 
S

Shauna Kelly

Hi Barb

There are lots of ways you could do that. Here's one:

If wdDoc Is Nothing Then
Set wdDoc = Documents.Add
End If

wdDoc.Range.InsertAfter oDoc.Name & vbCrLf

For i = 1 To 10
wdDoc.Range.InsertAfter i & vbTab & DataArray(i, 1) & vbTab &
DataArray(i, 2) & vbCrLf
Next i

'to save the document
wdDoc.Save

'or, to save and close the document
wdDoc.Close SaveChanges:=True

Hope this helps.

Shauna Kelly. Microsoft MVP.
http://www.shaunakelly.com/word
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top