发这个帖子没有别的意思,只怪我能力有问题,一个问题n天了还没解决。
法律很多帖子也无人解答,不知道问题问的太肤浅还是别的愿意,只有
发这么个标题来吸引人气,望大家海涵,原谅小弟。
我在VC中操作WORD向指定的页面插入图片。
下面是VBA代码。
Sub test()
    Dim Startpage As Long
    Dim mPage As String
    Dim myRange As Range
    Dim MyShape As Object    mPage = InputBox(prompt:="请在此输入页码!", Title:="Word页选定")
    If mPage = "" Then Exit Sub
    If mPage < 1 Then Exit Sub
    If mPage > ActiveDocument.BuiltInDocumentProperties("Number of Pages") Then
        MsgBox "超出页数范围", vbCritical
        Exit Sub
    End If
    With ActiveDocument
        Startpage = .GoTo(wdGoToPage, wdGoToNext, , mPage).Start
        Set myRange = .Range(.GoTo(wdGoToPage, wdGoToNext, , mPage).Start).Words(1)
        myRange.Select
        Set MyShape = .Shapes.AddPicture(ThisDocument.Path & "\1.jpg", , , 0, 0, , , myRange)
    End With
End Sub
一直到
Set MyShape = .Shapes.AddPicture(ThisDocument.Path & "\1.jpg", , , 0, 0, , , myRange)
语句之前,我都解决了,那么最后这条语句变为VC实在是没法搞定。也就是最后一个参数要怎样设置才能把一个CComQIPtr<MSWord::Range>  anchorRange;变量作为一个VARINAT * anchor参数传进去。
AddPicture函数在VC中的定义如下:
AddPicture(LPCTSTR FileName, VARIANT* LinkToFile, VARIANT* SaveWithDocument, VARIANT* Left, VARIANT* Top, VARIANT* Width, VARIANT* Height, VARIANT* Anchor);

解决方案 »

  1.   

    转化成IDispatch接口,
    这样试一试
    CComVariant cv(anchorRange);
      

  2.   

    http://community.csdn.net/IndexPage/SmartQuestion.aspx
    CComQIPtr<IDispatch>  dispAnchorRange(anchorRange);
    variant_t var(dispAnchorRange.p);
    VARIANT* pvar=&var;
      

  3.   

    非常感谢jiangsheng朋友的支持,其实你上次给我回了站内短信,但是我没看懂。。这次你给我写的这么详细,真的谢谢你了。。如果来你有时间来长沙的话,给我提前发站内短信,我非常希望能够接待你再次感谢也感谢wlwlxj的友情支持谢谢。