How to wrap a image which is call from excel? Disable Object

  • Thread starter teddy b via OfficeKB.com
  • Start date
T

teddy b via OfficeKB.com

Need help.

My image will call out from excel file then post it to the header of document.
The image is sit inside header Frame and table.

How to wrap it using vba? I'm trying Application.Options.PrintDrawingObjects
= False but not working. It's work only after i wrap it manualy on the image.


Below is my script:

With wb.Sheets(2)
LastRow = .Range("A65536").End(xlUp).Row
For z = 2 To LastRow
If (.Range("A" & z).Text) = "1" Then
'Check Image
If Len(Dir("C:\" & (.Range("A" & z).Text))) > 0 Then
FName = (.Range("A & z).Text)
With ActiveDocument.Sections(1).Headers
(wdHeaderFooterFirstPage).Range.Tables(1).Cell(1, 1).Range
.Delete
.InlineShapes.AddPicture FileName:="C:\" & FName,
LinkToFile:=False
End With
End If
End If
Next z
End With

Thanks.

Regards,
teddy
 
J

Jean-Guy Marcil

teddy b via OfficeKB.com was telling us:
teddy b via OfficeKB.com nous racontait que :
Need help.

My image will call out from excel file then post it to the header of
document. The image is sit inside header Frame and table.

How to wrap it using vba? I'm trying
Application.Options.PrintDrawingObjects = False but not working. It's
work only after i wrap it manualy on the image.


Below is my script:

With wb.Sheets(2)
LastRow = .Range("A65536").End(xlUp).Row
For z = 2 To LastRow
If (.Range("A" & z).Text) = "1" Then
'Check Image
If Len(Dir("C:\" & (.Range("A" & z).Text))) > 0 Then
FName = (.Range("A & z).Text)
With ActiveDocument.Sections(1).Headers
(wdHeaderFooterFirstPage).Range.Tables(1).Cell(1, 1).Range
.Delete
.InlineShapes.AddPicture FileName:="C:\" & FName,
LinkToFile:=False
End With
End If
End If
Next z
End With

You could do it like this:
'_______________________________________
Sub test1()
Dim myInlineShape As InlineShape
Dim myShape As Shape

With ActiveDocument.Sections(1).Headers(wdHeaderFooterFirstPage) _
.Range.Tables(1).Cell(1, 1).Range
.Delete
Set myInlineShape = .InlineShapes _
.AddPicture(FileName:="C:\" & FName, LinkToFile:=False)
With myInlineShape
Set myShape = .ConvertToShape
With myShape
.WrapFormat.Type = wdWrapSquare
End With
End With
End With

End Sub
'_______________________________________

But, if you are going to end up with a Shape, why use an InlineShape in the
first place?
Compare:

'_______________________________________
Sub test2()
Dim myInlineShape As InlineShape
Dim myShape As Shape

With ActiveDocument.Sections(1).Headers(wdHeaderFooterFirstPage) _
.Range.Tables(1).Cell(1, 1).Range
.Delete
Set myShape = ActiveDocument.Shapes _
.AddPicture(FileName:="C:\" & FName, _
LinkToFile:=False, Anchor:=.Paragraphs(1).Range)
With myShape
.WrapFormat.Type = wdWrapSquare
End With
End With

End Sub
'_______________________________________

--
Salut!
_______________________________________
Jean-Guy Marcil - Word MVP
[email protected]
Word MVP site: http://www.word.mvps.org
 
T

teddy b via OfficeKB.com

Thanks Jean. It's work.

What is the impact for these 2 methods?

Jean-Guy Marcil said:
teddy b via OfficeKB.com was telling us:
teddy b via OfficeKB.com nous racontait que :
Need help.
[quoted text clipped - 24 lines]
Next z
End With

You could do it like this:
'_______________________________________
Sub test1()
Dim myInlineShape As InlineShape
Dim myShape As Shape

With ActiveDocument.Sections(1).Headers(wdHeaderFooterFirstPage) _
.Range.Tables(1).Cell(1, 1).Range
.Delete
Set myInlineShape = .InlineShapes _
.AddPicture(FileName:="C:\" & FName, LinkToFile:=False)
With myInlineShape
Set myShape = .ConvertToShape
With myShape
.WrapFormat.Type = wdWrapSquare
End With
End With
End With

End Sub
'_______________________________________

But, if you are going to end up with a Shape, why use an InlineShape in the
first place?
Compare:

'_______________________________________
Sub test2()
Dim myInlineShape As InlineShape
Dim myShape As Shape

With ActiveDocument.Sections(1).Headers(wdHeaderFooterFirstPage) _
.Range.Tables(1).Cell(1, 1).Range
.Delete
Set myShape = ActiveDocument.Shapes _
.AddPicture(FileName:="C:\" & FName, _
LinkToFile:=False, Anchor:=.Paragraphs(1).Range)
With myShape
.WrapFormat.Type = wdWrapSquare
End With
End With

End Sub
'_______________________________________
 
J

Jean-Guy Marcil

teddy b via OfficeKB.com was telling us:
teddy b via OfficeKB.com nous racontait que :
Thanks Jean. It's work.

What is the impact for these 2 methods?

One inserts an inline shape and then converts it to a floating shape (as you
were doing in your first post), the other inserts a floating shape directly.

--
Salut!
_______________________________________
Jean-Guy Marcil - Word MVP
[email protected]
Word MVP site: http://www.word.mvps.org
 
Top