ExcelHome技术论坛

 找回密码
 免费注册

QQ登录

只需一步,快速开始

快捷登录

搜索
EH技术汇-专业的职场技能充电站 妙哉!函数段子手趣味讲函数 Excel服务器-会Excel,做管理系统 效率神器,一键搞定繁琐工作
HR薪酬管理数字化实战 Excel 2021函数公式学习大典 Excel数据透视表实战秘技 打造核心竞争力的职场宝典
让更多数据处理,一键完成 数据工作者的案头书 免费直播课集锦 ExcelHome出品 - VBA代码宝免费下载
用ChatGPT与VBA一键搞定Excel WPS表格从入门到精通 Excel VBA经典代码实践指南
楼主: 雨雪霏霏

[求助]设置自选图形的默认效果及画布增删

[复制链接]

TA的精华主题

TA的得分主题

发表于 2006-10-26 06:37 | 显示全部楼层
            AutoType = .AutoShapeType
            Select Case AutoType
            Case msoShapeFlowchartAlternateProcess
                Set myShape = Me.Shapes.AddShape(msoShapeFlowchartAlternateProcess, 0, 0, 0, 0)
            Case msoShapeFlowchartProcess
                Set myShape = Me.Shapes.AddShape(msoShapeFlowchartProcess, 0, 0, 0, 0)
            Case msoShapeMixed
                Set myShape = Me.Shapes.AddShape(msoShapeRectangle, 0, 0, 0, 0)
            Case msoShapeOval
                Set myShape = Me.Shapes.AddShape(msoShapeOval, 0, 0, 0, 0)
            Case Else
                Set myShape = Me.Shapes.AddShape(msoShapeRectangle, 0, 0, 0, 0)
            End Select
        Case msoLine
            Set myShape = Me.Shapes.AddLine(0, 0, 0, 0)
        Case msoTextBox
            Set myShape = Me.Shapes.AddTextbox(msoTextOrientationHorizontal, 0, 0, 0, 0)
        End Select
        myShape.Name = "mySetShapeDefault"
        myShape.Apply
        Me.Save
    End With
    Exit Sub
ErrHandle:
    myMsg = "
出错的过程名为
:SetDrawingDefaults" & vbCrLf
    myMsg = myMsg & Now & "
程序运行中发现错误:" & vbCrLf & "错误号:" & Err.Number & ",出错原因为
:" & Err.Description
    Err.Clear
    Call HandleError
End Sub
'----------------------
Sub ShowDialogbywdDialogFormatDrawingObject()
'
该对话框对画布中的图形将出错
.
    Dim myDialog As Dialog, N As String
    On Error GoTo ErrHandle
    N = Word.CommandBars.ActionControl.Caption
    Set myDialog = Word.Dialogs(wdDialogFormatDrawingObject)
    With myDialog


TA的精华主题

TA的得分主题

发表于 2006-10-26 06:38 | 显示全部楼层
        Select Case N
        Case "
线条与颜色
"
            .DefaultTab = 1200000
        Case "
大小
"
            .DefaultTab = 1200001
        Case "
版式
"
            .DefaultTab = 1200002
        Case "
文本框
"
            .DefaultTab = 1200005
        End Select
        .Show
    End With
    Exit Sub
ErrHandle:
    myMsg = "
出错的过程名为
:ShowDialogbywdDialogFormatDrawingObject" & vbCrLf
    myMsg = myMsg & Now & "
程序运行中发现错误:" & vbCrLf & "错误号:" & Err.Number & ",出错原因为
:" & Err.Description
    Err.Clear
    Call HandleError
End Sub
'----------------------
Sub HandleError()
    MsgBox myMsg, vbExclamation, msgTitle
    If MsgBox("
是否需要发送错误报告
?", vbQuestion + vbYesNo, msgTitle) = vbYes Then MailToAuthor
End Sub
'----------------------
Sub MailToAuthor()
'
错误报告到作者

    Dim ShouRouMail1 As String, ShouRouMail2 As String
    On Error Resume Next
    ShouRouMail1 = "shourou@ExcelHome.net"
    ShouRouMail2 = "shourou_8@hotmail.com"
    ThisDocument.FollowHyperlink _
            "MailTo:" & ShouRouMail1 & "?Subject=Error Report" & "&CC=" & ShouRouMail2 & _
                      "&Body=" & msgTitle & " Find These Error:" & myMsg
End Sub
'----------------------

Option Explicit
Sub DelCanvas()
'
删除画布保留图形,即将画布内图形原样移出,删除该画布

TA的精华主题

TA的得分主题

发表于 2006-10-26 06:39 | 显示全部楼层
    Dim shpCanvas As Shape
    Dim shpCanvasShapes As CanvasShapes
    With Selection
        If .Type = wdSelectionShape Then    '
如果所选的是图形的话

            If .ShapeRange(1).Type = msoCanvas Then    '
如果所选图形是画布(画布中的某个图形)
                Set shpCanvas = .ShapeRange(1)
                Set shpCanvasShapes = shpCanvas.CanvasItems
                shpCanvasShapes.SelectAll
                .Cut
                .Delete
                .Paste
            End If
        End If
    End With
End Sub
'----------------------
Sub AddCanvas()
'
将非画布中的图形组合
,
    Dim shpCanvas As Shape, GW As Single, GH As Single
    Dim myShape As Shape, myLine As Shape, TF As Boolean
    Dim myRange As Range
    Application.ScreenUpdating = False
    With Selection
        If .Type = wdSelectionShape Then    '
如果所选的是图形的话

            If .ShapeRange(1).Type = msoGroup Then   '
如果所选图形是组合图形
                Set myShape = .ShapeRange(1)
                Set myRange = ActiveDocument.Range(.Paragraphs(1).Range.Start, .Paragraphs(1).Range.Start)
                '
此句判断是段首或是段尾,若是段尾,TF=TRUE
                If VBA.Asc(.Paragraphs(1).Range.Characters.First) <> 1 Then TF = True
                With myShape    '
修改图片格式

                    .WrapFormat.Type = wdWrapSquare
                    GW = .Width
                    GH = .Height
                    .Select
                End With
                .Cut
                '
此处宽度和高度的增加量,视实际情况调整为某个固定值
                Set shpCanvas = ActiveDocument.Shapes.AddCanvas(Left:=0, Top:=0, Width:=GW + 1,

TA的精华主题

TA的得分主题

发表于 2006-10-26 06:43 | 显示全部楼层

Height:=GH + 1, Anchor:=myRange)
                Set myLine = shpCanvas.CanvasItems.AddLine(0, 0, 0, 0)
                myLine.Select
                Selection.Delete
                .Paste
                shpCanvas.CanvasItems.SelectAll
                Application.Run "DrawUngroup"    '
取消组合

                shpCanvas.WrapFormat.Type = wdWrapInline '
嵌入式图形格式
                If TF = True Then
                    shpCanvas.Select
                    .Cut
                    '
定义一个RANGE对象,为段尾位置
                    Set myRange = ActiveDocument.Range(.Paragraphs(1).Range.End - 1, .Paragraphs(1).Range.End - 1)
                    myRange.Select
                    .Paste
                End If
            End If
        End If
    End With
    Application.ScreenUpdating = True
End Sub
'----------------------


成品如下,请下载后以加载项形式加载。

WXiOv7v2.rar (11.48 KB, 下载次数: 59)


[求助]设置自选图形的默认效果及画布增删

[求助]设置自选图形的默认效果及画布增删

vyC2gdxd.rar

24.51 KB, 下载次数: 67

[求助]设置自选图形的默认效果及画布增删

TA的精华主题

TA的得分主题

发表于 2006-10-26 08:26 | 显示全部楼层
[广告] VBA代码宝 - VBA编程加强工具 · VBA代码随查随用  · 内置多项VBA编程加强工具       ★ 免费下载 ★      ★使用手册
想当年,我多么需要这个功能其中的删除画布功能啊。呵呵。

TA的精华主题

TA的得分主题

发表于 2007-2-10 18:01 | 显示全部楼层

TA的精华主题

TA的得分主题

发表于 2007-2-10 23:37 | 显示全部楼层
[广告] Excel易用宝 - 提升Excel的操作效率 · Excel / WPS表格插件       ★免费下载 ★       ★ 使用帮助
技术狂人:老大!!![em06]

TA的精华主题

TA的得分主题

发表于 2008-3-27 20:45 | 显示全部楼层

TA的精华主题

TA的得分主题

发表于 2008-3-28 15:32 | 显示全部楼层
这个不是有整理好的吗?我上传下,有需要的直接下就好了

TA的精华主题

TA的得分主题

发表于 2008-6-18 23:20 | 显示全部楼层
您需要登录后才可以回帖 登录 | 免费注册

本版积分规则

手机版|关于我们|联系我们|ExcelHome

GMT+8, 2024-11-24 12:44 , Processed in 0.043490 second(s), 7 queries , Gzip On, MemCache On.

Powered by Discuz! X3.4

© 1999-2023 Wooffice Inc.

沪公网安备 31011702000001号 沪ICP备11019229号-2

本论坛言论纯属发表者个人意见,任何违反国家相关法律的言论,本站将协助国家相关部门追究发言者责任!     本站特聘法律顾问:李志群律师

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