123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341 |
- Dim cdr As CorelDRAW.Application
- Set cdr = CreateObject("corelDRAW.Application.14")
- MsgBox "文件名:" & cdr.ActiveDocument.FileName & "目录:" & cdr.ActiveDocument.FilePath
- MsgBox "目录和文件名:" & cdr.ActiveDocument.FullFileName
- Document Member
- Activate
- ActiveLayer
- ActivePage
- AddPages AddPagesEx
- BeginCommandGroup EndCommandGroup
- ClearSelection
- Close
- Export
- ExportEx
- ExportBitmap
- FileName
- FilePath
- FullFileName
- GetUserArea
- GetUserClick
- InsertPages InsertPagesEx
- Pages
- Printout PrintSettings
- PublishToPDF PDFSettings
- ReferencePoint
- Save
- SaveAs
- Selection
- SelectionRange
- Unit
- Worldscale
- Dim d As Document
- Set d = CreateDocument
- d.ActiveLayer.Import "R:\CDX4JX\ColorMark.cdr"
- d.SaveAs "学习VBA新文档.cdr"
- MsgBox d.FileName & " 目录: " & d.FilePath
- f = d.FullFileName
- d.Close
- Dim doc As Document
- Set doc = OpenDocument(f)
- ActiveDocument.Export "R:\学习VBA新文档.jpg", cdrJPEG
- ActiveDocument.Export "R:\学习VBA新文档.eps", cdrEPS
- ActiveDocument.Unit = cdrMillimeter
- ActivePage.SetSize 210, 297
- ActivePage.Orientation = cdrLandscape
- Dim doc As Document
- Set doc = ActiveDocument
- doc.Unit = cdrMillimeter
- doc.Pages(0).SetSize 297, 210
- ActivePage.Delete
- If ActiveDocument.Pages.Count > 1 Then ActivePage.Delete
- ActivePage.CreateLayer "刀模线图层"
- ActivePage.Layers("刀模线图层").Activate
- ActivePage.Layers("刀模线图层").Visible = True
- ActivePage.Layers("刀模线图层").Editable = False
- 形状对象表示您使用绘图工具在 CorelDRAW 文档中创建的形状。您可以创建的形状包括矩形、椭圆、曲线和文本对象。
- 因为每个 Shape 对象都是 Shapes 集合的成员,它是 Page 上的其中一个 Layer 对象的成员,所以用于创建新形状的方法属于 Layer 类,它们都以单词 Create 开头。
- Dim sh As Shape
- ActiveDocument.Unit = cdrInch
- Set sh = ActiveLayer.CreateRectangle(3, 7, 6, 5)
- Dim sh As Shape
- ActiveDocument.Unit = cdrInch
- Set sh = ActiveLayer.CreateRectangle2(3, 6, 2, 1)
- Dim sh As Shape
- ActiveDocument.Unit = cdrInch
- Set sh = ActiveLayer.CreateRectangle(3, 7, 6, 5, 100, 75, 50 ,0)
- Set sh = ActiveLayer.CreateRectangle2(3, 7, 6, 5, 1, 1.5, 2, 0)
- Dim sh As Shape
- ActiveDocument.Unit = cdrMillimeter
- Set sh = ActiveLayer.CreateEllipse(75, 150, 125, 100)
- Dim sh As Shape
- ActiveDocument.Unit = cdrMillimeter
- Set sh = ActiveLayer.CreateEllipse2(100, 125, 25)
- Set sh = ActiveLayer.CreateEllipse2(100, 125, 50, 25)
- Dim sh As Shape, spath As SubPath, crv As Curve
- ActiveDocument.Unit = cdrCentimeter
- Set crv = Application.CreateCurve(ActiveDocument)
- Set spath = crv.CreateSubPath(6, 6)
- spath.AppendLineSegment 6, 3
- spath.AppendCurveSegment 3, 0, 2, 270, 2, 0
- spath.AppendLineSegment 0, 0
- spath.AppendLineSegment 0, 9
- spath.AppendLineSegment 3, 9
- spath.AppendCurveSegment 6, 6, 2, 0, 2, 90
- spath.Closed = True
- Set sh = ActiveLayer.CreateCurve(crv)
- Dim sh As Shape
- Set sh = ActiveLayer.CreateArtisticText(0, 0, "Hello World")
- Dim sh As Shape
- Set sh = ActivePage.Shapes(1)
- If sh.Selected = False Then sh.CreateSelection
- ActivePage.Shapes(3).Selected = True
- ActiveDocument.ClearSelection
- ActivePage.Shapes.All.CreateSelection
- Dim sel As Shape
- Set sel = ActiveDocument.Selection
- MsgBox "选择物件尺寸: " & sel.SizeWidth & "x" & sel.SizeHeight
- Dim sh As Shape, shs As Shapes
- Set shs = ActiveSelection.Shapes
- For Each sh In shs
- MsgBox "选择物件尺寸: " & sh.SizeWidth & "x" & sh.SizeHeight
- Next sh
- ActiveDocument.Unit = cdrMillimeter
- Dim OrigSelection As ShapeRange, sh As Shape
- Set OrigSelection = ActiveSelectionRange
- Set sh = OrigSelection.Group
- MsgBox "选择物件尺寸: " & sh.SizeWidth & "x" & sh.SizeHeight
- ActivePage.SetSize Int(sh.SizeWidth + 0.9), Int(sh.SizeHeight + 0.9)
- sh.AlignToPageCenter cdrAlignHCenter + cdrAlignVCenter
- cdrAlignLeft 1 指定左对齐
- cdrAlignRight 2 指定右对齐
- cdrAlignHCenter 3 指定水平居中对齐
- cdrAlignTop 4 指定顶部对齐
- cdrAlignBottom 8 指定底部对齐
- cdrAlignVCenter 12 指定垂直居中对齐
- Dim s1 As Shape
- Set s1 = ActiveLayer.CreateRectangle2(0, 0, 210, 297)
- s1.Fill.ApplyNoFill
- s1.OrderToFront
- s1.OrderToBack
- s1.Outline.SetProperties 0.04, Color:=CreateCMYKColor(0, 100, 0, 0)
- s1.Move 100, 0#
- s1.Move 0#, -61.8
- Dim posX As Double, posY As Double
- ActiveDocument.ReferencePoint = cdrBottomLeft
- s1.GetPosition posX, posY
- MsgBox "左下坐标: " & posX & ", " & posY
- Dim sh As Shape
- ActiveDocument.Unit = cdrInch
- ActiveDocument.ReferencePoint = cdrBottomRight
- For Each sh In ActiveSelection.Shapes
- sh.SetPosition 3, 2
- Next sh
- Dim sh As Shape
- Set sh = ActiveDocument.Selection
- sh.AlignToPage cdrAlignHCenter + cdrAlignTop
- sh.Duplicate 0, 0
- sh.Rotate 180
- sh.AlignToPage cdrAlignHCenter + cdrAlignBottom
- sh.Duplicate 0, 0
- sh.Rotate 90
- sh.AlignToPage cdrAlignVCenter + cdrAlignRight
- sh.Duplicate 0, 0
- sh.Rotate 180
- sh.AlignToPage cdrAlignVCenter + cdrAlignLeft
- Dim sh As Shape
- Set sh = ActiveDocument.Selection
- sh.AlignToPage cdrAlignLeft + cdrAlignTop
- sh.Duplicate 0, 0
- sh.Rotate 180
- sh.AlignToPage cdrAlignRight + cdrAlignBottom
- sh.Duplicate 0, 0
- sh.Flip cdrFlipHorizontal
- sh.AlignToPage cdrAlignLeft + cdrAlignBottom
- sh.Duplicate 0, 0
- sh.Rotate 180
- sh.AlignToPage cdrAlignRight + cdrAlignTop
- Sub get_all_size()
- ActiveDocument.Unit = cdrMillimeter
- Set fs = CreateObject("Scripting.FileSystemObject")
- Set f = fs.CreateTextFile("R:\size.txt", True)
- Dim sh As Shape, shs As Shapes
- Set shs = ActiveSelection.Shapes
- Dim s As String
- For Each sh In shs
- size = Trim(Str(Int(sh.SizeWidth + 0.5))) + "x" + Trim(Str(Int(sh.SizeHeight + 0.5))) + "mm"
- f.WriteLine (size)
- s = s + size + vbNewLine
- Next sh
- f.Close
- MsgBox "输出物件尺寸信息到文件" & "R:\size.txt" & vbNewLine & s
- WriteClipBoard s
- End Sub
- Private Function WriteClipBoard(s As String)
- On Error Resume Next
- Dim MyData As New DataObject
- MyData.SetText s
- MyData.PutInClipboard
- End Function
- Sub 加ID()
- ActiveDocument.Unit = cdrMillimeter
- Dim n As String
- Dim s1 As Shape
- Dim s As Shape
- Set s = ActiveShape
- If s Is Nothing Then
- MsgBox "请选择一个图形"
- Exit Sub
- End If
- n = vba.GetSetting("addID", "nm", "id")
- If n = "" Then
- n = "1"
- vba.SaveSetting "addID", "nm", "id", "1"
- Else
- n = CStr(Val(vba.GetSetting("addID", "nm", "id")) + 1)
- vba.SaveSetting "addid", "nm", "id", n
- End If
- Set s1 = ActiveLayer.CreateArtisticText(0, 0, "ID " & n, , , , 30)
- s1.CenterX = s.CenterX
- s1.CenterY = s.CenterY
- End Sub
- Sub find_id()
- Find_Text "ID"
- End Sub
-
- Public Function Find_Text(s_s As String)
- Dim s As Shape
- For Each s In ActivePage.FindShapes(, cdrTextShape)
-
- If s.Text.Type = cdrArtisticText And InStr(s.Text.Story, s_s) <> 0 Then
-
- s.AddToSelection
- End If
- Next s
- End Function
- Public SystemX As Long
- Public SystemY As Long
- Private Declare Function GetSystemMetrics Lib "user32" (ByVal nIndex As Long) As Long
- Public Function filePath()
- filePath = Application.Path & "GMS"
- End Function
- Function GetSysM(SystemX As Long, SystemY As Long)
- Dim XVal As Long, YVal As Long
- SystemX = GetSystemMetrics(0)
- SystemY = GetSystemMetrics(1)
- GetSysM = SystemX & "#" & SystemY
- End Function
|