找回密码
 加入
搜索
楼主: kk_lee69

[系统综合] WORD VBA 语法相关定位问题 求高手帮我看一下少了甚么步骤

 火..   [复制链接]
 楼主| 发表于 2017-8-3 10:15:20 | 显示全部楼层
回复 29# oceanwind

怪事  我測試的結果 還是依樣  到底是哪邊的環境有問題

本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有账号?加入

×
发表于 2017-8-3 13:28:28 | 显示全部楼层
回复 30# kk_lee69
昨天下载你的图片显示像素是400,今天下载又显示是96了。如图为ps图像调整大小时的对话框。
你还是对不准,是不是shaps的属性RelativeHorizontalPosition 要多试一下
用法:
With ActiveDocument.Shapes("split#=" & ii)
              .RelativeHorizontalPosition = wdRelativeHorizontalPositionPage
              .Left = pgwd - mywidth - temp_edge '靠右边
              .RelativeVerticalPosition = wdRelativeVerticalPositionPage
              .Top = temp_topwz
             
        End With
WdRelativeHorizontalPosition 。
枚举
指定图文框、形状或一组行的水平位置所相对的对象。
版本信息
已添加版本:  

名称 值 说明
wdRelativeHorizontalPositionCharacter 3 相对于字符。
wdRelativeHorizontalPositionColumn 2 相对于列。
wdRelativeHorizontalPositionMargin 0 相对于边距。
wdRelativeHorizontalPositionPage 1 相对于页面。
wdRelativeHorizontalPositionInnerMarginArea 6 相对于内空白区。
wdRelativeHorizontalPositionLeftMarginArea 4 相对于左边距。
wdRelativeHorizontalPositionOuterMarginArea 7 相对于外空白区。
wdRelativeHorizontalPositionRightMarginArea 5 相对于右边距。
另外由于改成1.6宽,txt宽度要适当调宽一些,我又改微调了一下,我在公司的电脑2010也可行:
Sub insertpic()
    '
    ' 筿?彻?ボ虫ノ
    '
    
    PLeft = Selection.Information(wdHorizontalPositionRelativeToPage)
    PTop = Selection.Information(wdVerticalPositionRelativeToPage)
    PLPOS = Selection.Information(wdHorizontalPositionRelativeToTextBoundary)
    
    Dim Sh1, Sh2 As Object, PS As Object
    Set PS = ThisDocument.PageSetup
    
    'MsgBox (PLeft & "  " & PTop)
    
    Dim arr(0 To 1) As Variant
    
    Set myDocument = ActiveDocument
    With myDocument.Shapes
        
        With .AddPicture(FileName:="E:\SW\Studydoc\office\word\Au3_KK_lee69 problem\2\999_2.jpg", LinkToFile:=False, SaveWithDocument:=True, Left:=PS.LeftMargin, Top:=PS.TopMargin)
            .Name = "shp1"
            arr(0) = .Name
            
        End With
        
        
        
        Set Sh1 = ThisDocument.Shapes("shp1")
        
        Sh1.Select
        
        With ThisDocument.Shapes.AddTextbox(msoTextOrientationHorizontal, PS.LeftMargin, PS.TopMargin, Sh1.Width * 2, Sh1.Height)
            .Name = "shp2"
            .Line.Visible = msoFalse
            .Fill.Transparency = 1
            With .TextFrame
                .VerticalAnchor = msoAnchorMiddle
                With .TextRange
                    .ParagraphFormat.Alignment = wdAlignParagraphCenter
                    .Font.Size = 7.5
                    '.Font.Name = "夹发砰"
                    .Font.ColorIndex = wdBlue
                    .Text = Format(Date, "yyyy.mm.dd")
                End With
            End With
        End With
        
         Set Sh2 = ThisDocument.Shapes("shp2")
         
        Dim target_left, target_top As Single
        
        
        With Sh1
            target_left = .Left
            target_top = .Top
        End With
        
       
        
        With Sh2
            
            .Left = target_left - (Sh1.Width / 2)
          
            .Top = target_top
        End With
        
        
        
        ' With .Range(Array("shp1", "shp2")).Group
        '.Fill.PresetTextured msoTextureBlueTissuePaper
        '.Rotation = 45
        ' .ZOrder msoSendToBack
        ' End With
        
        
    End With
    
End Sub

本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有账号?加入

×
发表于 2017-8-3 13:32:00 | 显示全部楼层
本帖最后由 oceanwind 于 2017-8-3 13:35 编辑


这些公司电脑中运行行代码后截图。小蓝图我已在ps中去掉了白边。

本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有账号?加入

×
 楼主| 发表于 2017-8-3 13:49:59 | 显示全部楼层
回复 32# oceanwind


    我試看看  另外請教 你貼的圖片 是哪套 圖形處理軟體   可以看到 釐米的 我想找來用看看
发表于 2017-8-3 13:57:28 | 显示全部楼层
回复 34# kk_lee69
photoshop cc 2015
 楼主| 发表于 2017-8-3 14:02:58 | 显示全部楼层
回复 35# oceanwind


    果然是專業繪圖軟體  呵呵  了解 感謝
 楼主| 发表于 2017-8-3 14:30:42 | 显示全部楼层
回复 32# oceanwind


    能夠請教一下嗎
SaveWithDocument:=True, Left:=PS.LeftMargin, Top:=PS.TopMargin)

PS.LeftMargin 代表甚麼位置 我看上面語法 沒有先把值 賦給 PS.LeftMargin 這個變數阿
发表于 2017-8-3 19:31:48 | 显示全部楼层
回复 37# kk_lee69
第一次遇到这个表达式。对vba也是不求甚解,刚好工作中也有遇到与你类似问题怎样去控制图片的位置。
应该是看了你的代码还是高手kevinch的后查了msdn.

Returns a PageSetup object that is associated with the specified document.

Syntax

expression . PageSetup

expression A variable that represents a Document object.

Example

This example sets the right margin of the active document to 72 points (1 inch).

ActiveDocument.PageSetup.RightMargin = InchesToPoints(1)
This example displays the left margin setting, in inches.

MsgBox PointsToInches(ActiveDocument.PageSetup.LeftMargin) _
&; " inches"
发表于 2017-8-3 19:35:28 | 显示全部楼层
不过因为后面又重设置了left与top,所以最终结果与ps.leftmargin没啥直接关系了。
您需要登录后才可以回帖 登录 | 加入

本版积分规则

QQ|手机版|小黑屋|AUTOIT CN ( 鲁ICP备19019924号-1 )谷歌 百度

GMT+8, 2024-4-19 23:43 , Processed in 0.075760 second(s), 14 queries .

Powered by Discuz! X3.5 Licensed

© 2001-2024 Discuz! Team.

快速回复 返回顶部 返回列表