the AddOLEControl method make the print behavior of Word different

P

Philip Chan

When I add an ActiveX Control into word2000 with the following VBA code:

Sub demo()
Dim sp As Shape
Set sp =
ActiveDocument.Shapes.AddOLEControl("GABSignatureOffice.SignatureCtrl")
With sp.WrapFormat
.Type = wdWrapNone
.Side = wdWrapBoth
.AllowOverlap = True
End With
sp.ZOrder msoSendBehindText
sp.LockAspectRatio = msoTrue
Set sp = Nothing
End Sub

When the document was printed, the control is under the text as I expected.
Well, when I do the same work by a COM Addin with the following code:

CComPtr<Word::Shapes> pShapes;
hr = pDoc->get_Shapes(&pShapes);
ATLASSERT(SUCCEEDED(hr));
CComPtr<Word::Shape> pShape;
hr =
pShapes->AddOLEControl(&CComVariant(_T("GABSignatureOffice.SignatureCtrl")),
&vtMissing, &vtMissing, &vtMissing, &vtMissing, &vtMissing, &pShape);
ATLASSERT(SUCCEEDED(hr));
CComPtr<Word::WrapFormat> pWrapFormat;
hr = pShape->get_WrapFormat(&pWrapFormat);
ATLASSERT(SUCCEEDED(hr));
hr = pWrapFormat->put_Type(Word::wdWrapNone);
ATLASSERT(SUCCEEDED(hr));
hr = pWrapFormat->put_AllowOverlap(VARIANT_TRUE);
ATLASSERT(SUCCEEDED(hr));
hr = pWrapFormat->put_Side(Word::wdWrapBoth);
ATLASSERT(SUCCEEDED(hr));
hr = pShape->ZOrder(Office::msoSendBehindText);
ATLASSERT(SUCCEEDED(hr));
hr = pShape->put_LockAspectRatio(Office::msoTrue);
ATLASSERT(SUCCEEDED(hr));

the control was printed in front of text. What's the problem?
 
P

Philip Chan

I know where the problem is. the following VBA code is to reproduce the
behavior

Sub demo()
Dim sp As Shape
Dim sec As Section
Dim headers As HeadersFooters
Dim header As HeaderFooter
Dim temRange As Range
Dim i As Integer

Set sp = ActiveDocument.Shapes.AddOLEControl("WMPlayer.OCX")
With sp.WrapFormat
.Type = wdWrapNone
.Side = wdWrapBoth
.AllowOverlap = True
End With
sp.ZOrder msoSendBehindText
sp.LockAspectRatio = msoTrue
Set sp = Nothing

Set sec = ActiveDocument.Sections(1)
Set headers = sec.headers

For i = 1 To 3
Set header = headers.Item(i)
If (header.Exists) Then
Set temRange = header.Range 'we just get the range and no
nothing
Set temRange = Nothing
End If
Set header = Nothing
Next i

Set sec = Nothing
Set headers = Nothing
End Sub


I don't know how to solve the problem. What if someone need to get the
content of headers of footers?
 
Top