Inserting a Pic into a Word doc.

zocker
08-11-2001, 08:10 AM
I am driving Word from Access, I want to take some text from a form and add a Pic, I've got this code and so far I'm successful except for the insert a Pic bit. I assembled this from recording a macro in Word and re-using (some of) the code. Heres the code I got so far.

Thanks in advance.


Private Sub WordIt_Click()
On Error GoTo Err_WordIt_Click

Dim strAdress As String
Dim strNotes As String
Dim oApp As Object

strAdress = Me!txtAddress
strNotes = Me!txtNotes

Set oApp = CreateObject("Word.Application")

oApp.Visible = True
oApp.CommandBars("Drawing").Visible = True
oApp.Documents.Add Template:="C:\Program Files\Microsoft Office\Templates\Empty.dot",

NewTemplate:=False

'**********
'Some code here inserts Text from an Access form - no probs with that.
'**********



'Dont know why I should have the next line!

oApp.CommandBars("Drawing").Visible = True

'All OK to here now it fails on the next line with the error message "The specified value is out of range" Seems to refer to 'the values
'Have changed values endlessly to find acceptable ones......no dice

oApp.ActiveDocument.Shapes.AddTextbox(msoTextOrientationHorizontal, 86, 86, 260, 280).Select


oApp.Selection.ShapeRange.TextFrame.TextRange.Select
oApp.Selection.Collapse
oApp.ChangeFileOpenDirectory "C:\My Pictures\"
oApp.Selection.InlineShapes.AddPicture FileName:= _
"C:\My Pictures\20Sep00003.JPG", LinkToFile:=False, SaveWithDocument:= _True

oApp.ActiveDocument.Close SaveChanges:=True

'CloseRunning is a function defined in a module

CloseRunning ("Word")


End Sub

Thinker
08-11-2001, 08:34 AM
I tried something similar. I have no Empty.dot template so I just used Normal.dot. When I swap back over to Word, there is the new document with the textbox. Is it possible that your empty.dot doesn't create a new document that is suitable for placing a textbox on?
BTW, both lines of code
oApp.CommandBars("Drawing").Visible = True
aren't needed unless someone is actually using the Word document and needs access to the Drawing Toolbar. Even if this is the case, you should still only need one of the lines.

I think therefore I am... sometimes right. images/icons/wink.gif

zocker
08-11-2001, 03:10 PM
Thanks but that didn't do it, I stlii get 'Value out of Range' The err.number is 9 (you guessed - value out of r......)

Thanks again

Thinker
08-11-2001, 03:57 PM
Although it probably wouldn't have made any difference, I should have asked this earlier. Did you go to the tools menu - References and set a reference to Microsoft Word 9.0 Object Library? (8.0 for office97)

I think therefore I am... sometimes right. images/icons/wink.gif

zocker
08-13-2001, 06:09 PM
Yes I did that. I go this to work. The pic is inserted at Top left of 1st page of doc. If the code insertes another pic the 2nd pic goes in the same place - atop the first pic. Heres the code I got to:

Option Compare Database



Private Sub Command0_Click()
On Error GoTo Err_Command0_Click



Dim strAdress As String
Dim strNotes As String
Dim PicPath As String

PicPath = "C:\my Pictures\1.jpg" 'pic the HOUSE
PicPath2 = "C:\my Pictures\2.jpg" 'Pic the OWNER
strAdress = Me!txtAddress
strNotes = Me!txtNotes

Dim oApp As Object




Set oApp = CreateObject("Word.Application")
oApp.Visible = True
oApp.CommandBars("Drawing").Visible = True
oApp.Documents.Add Template:="C:\Program Files\Microsoft Office\Templates\Empty.dot", NewTemplate:=False


oApp.Selection.TypeText Text:=strAdress
oApp.Selection.TypeParagraph
oApp.Selection.Font.Bold = 1

oApp.Selection.TypeText Text:=strNotes
oApp.Selection.TypeParagraph
oApp.Selection.TypeParagraph


oApp.Selection.Font.Size = 16
oApp.Selection.Font.Name = "Arial"
oApp.Selection.Font.Bold = 0
oApp.Selection.TypeText Text:=strNotes
oApp.Selection.TypeParagraph



'Dim w As Integer
'Dim x As Integer
'Dim y As Integer
'Dim z As Integer
'
'
'w = 86
'x = 86
'y = 260
'z = 280
'
'
'oApp.CommandBars("Drawing").Visible = True
' oApp.ActiveDocument.Shapes.AddTextbox(msoTextOrientationHorizontal, w, x, y, z).Select
'
' oApp.Selection.ShapeRange.TextFrame.TextRange.Select
' oApp.Selection.Collapse
' oApp.ChangeFileOpenDirectory "C:\My Pictures\"
' oApp.Selection.InlineShapes.AddPicture FileName:= _
' "C:\My Pictures\20Sep00003.JPG", LinkToFile:=False, SaveWithDocument:= _
' True
'ActiveDocument.Shapes.AddPicture _
' "C:\Program Files\Microsoft office\" _
' & "Office\Bitmaps\Styles\stone.bmp", _
' True, True
'ActiveDocument.Paragraphs(1).Range.Style = wdStyleHeading1

oApp.ActiveDocument.Shapes.AddPicture PicPath2, LinkToFile:=False, SaveWithDocument:=True

Selection.InsertBreak Type:=wdPageBreak 'no effect on doc

DoEvents

oApp.Selection.MoveDown Count:=3 'no effect

oApp.ActiveDocument.Shapes.AddPicture PicPath, LinkToFile:=False, SaveWithDocument:=True
'
' oApp.ActiveDocument.Shapes.AddTextbox(msoTextOrientationHorizontal, 86.4, _
' 216, 460.8, 230.4).Select
' oApp.Selection.ShapeRange.TextFrame.TextRange.Select
' oApp.Selection.Collapse
'


'oApp.ActiveDocument.Close SaveChanges:=True
'CloseRunning ("Word")

Exit_Command0_Click:
Exit Sub

Err_Command0_Click:
MsgBox Err.Description & " " & Err.Number
Resume Exit_Command0_Click

End Sub

EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum