V
Vincent Verheul
Hi,
I'm using MsAccess 2002 on a Windows XP machine. In Visual Basic for
Applications (VBA) which is part of the Access application, I use the Word
library to generate Word documents. One of the actions is to insert images
into the text. This worked perfectly until after I applied the Service Pack
2 for XP. Now I only see a small Icon with the file-name below it, but no
image itself. When I insert the image (from file) manually, it works OK.
Does this have to do with an expected "virus hazard" where Word is blocking
such actions coming from VBA?
Below the sample VBA code that demonstrates the effect:
Sub InsertImageInWord()
Const ImageMaxWidthPoints = 500
Dim wrd As Word.Application
Dim doc As Word.Document
Dim Shp As Word.InlineShape
Dim PicSize As Variant
' Word must be running prior to executing this code
Set wrd = GetObject(, "Word.Application")
Set doc = wrd.Documents.Add(DocumentType:=wdNewBlankDocument)
wrd.Visible = True
With wrd.Selection
.TypeParagraph
.TypeText "Test insert image with VBA"
.TypeParagraph
' Insert as an InlineShape
Set Shp = doc.InlineShapes.AddOLEObject("PhotoEdit", _
"C:\Data\MyImage.jpg", , False, , , , Selection.Range)
' Resize if wider than ImageMaxWidthPoints
PicSize = 1
If Shp.Width > ImageMaxWidthPoints Then PicSize = ImageMaxWidthPoints /
Shp.Width
Shp.ScaleHeight = Shp.ScaleHeight * PicSize
Shp.ScaleWidth = Shp.ScaleWidth * PicSize
.TypeParagraph
End With
End Sub
I'm using MsAccess 2002 on a Windows XP machine. In Visual Basic for
Applications (VBA) which is part of the Access application, I use the Word
library to generate Word documents. One of the actions is to insert images
into the text. This worked perfectly until after I applied the Service Pack
2 for XP. Now I only see a small Icon with the file-name below it, but no
image itself. When I insert the image (from file) manually, it works OK.
Does this have to do with an expected "virus hazard" where Word is blocking
such actions coming from VBA?
Below the sample VBA code that demonstrates the effect:
Sub InsertImageInWord()
Const ImageMaxWidthPoints = 500
Dim wrd As Word.Application
Dim doc As Word.Document
Dim Shp As Word.InlineShape
Dim PicSize As Variant
' Word must be running prior to executing this code
Set wrd = GetObject(, "Word.Application")
Set doc = wrd.Documents.Add(DocumentType:=wdNewBlankDocument)
wrd.Visible = True
With wrd.Selection
.TypeParagraph
.TypeText "Test insert image with VBA"
.TypeParagraph
' Insert as an InlineShape
Set Shp = doc.InlineShapes.AddOLEObject("PhotoEdit", _
"C:\Data\MyImage.jpg", , False, , , , Selection.Range)
' Resize if wider than ImageMaxWidthPoints
PicSize = 1
If Shp.Width > ImageMaxWidthPoints Then PicSize = ImageMaxWidthPoints /
Shp.Width
Shp.ScaleHeight = Shp.ScaleHeight * PicSize
Shp.ScaleWidth = Shp.ScaleWidth * PicSize
.TypeParagraph
End With
End Sub