PDA

View Full Version : Sending Info from Excel to Word



hnnssyvpr
09-01-2007, 06:52 AM
I have a spreadsheet that resembles this:

A B
0 Perform next step on vehicles equipped with cab radio.
0
0 Disconnect two power connectors (3) from two harness
0 connectors (4).
0
1 k:\wmfs\Rv06r02.wmf
0
0 Remove screw (5), and relay (6) from motor cover (7).

I want to insert the text (in column B) in Word wherever there is a 0 in column A and where there is a 1 in column A, i want to insert a picture into Word that is located at the path given.
I am WAS able to do the text part last night without issues but that doesn't work for some reason anymore:banghead: . I am currently using SendKeys and am able to get the Insert Picture box to come up but can't get the link to come in.
Anyone have any advice for me?

mdmackillop
09-01-2007, 09:32 AM
Hi hnnssyvpr
Welcome to VBAX
Nice choice of username. Very memorable and just rolls off the tongue.

Sub AddStuffToWord()
Dim wdApp As Object
Dim myRange
Set wdApp = CreateObject("word.application")
wdApp.Visible = True
Set wdDoc = wdApp.Documents.Add
Set myRange = wdDoc.Range
For Each cel In Range(Cells(1, 1), Cells(1, 1).End(xlDown))
With myRange
.MoveEnd
.Collapse Direction:=wdCollapseEnd
.InsertParagraphAfter
Select Case cel
Case 0
.InsertAfter cel.Offset(, 1).Text
Case 1
.InlineShapes.AddPicture Filename:="k:\wmfs\Rv06r02.wmf ", LinkToFile:= _
False, SaveWithDocument:=True
End Select
End With
Next
'wdApp.Quit
'Set wdApp = Nothing
End Sub