ExcelHome技术论坛

 找回密码
 免费注册

QQ登录

只需一步,快速开始

快捷登录

搜索
EH技术汇-专业的职场技能充电站 妙哉!函数段子手趣味讲函数 Excel服务器-会Excel,做管理系统 效率神器,一键搞定繁琐工作
Python自动化办公应用大全 Excel 2021函数公式学习大典 Kutools for Office 套件发布 打造核心竞争力的职场宝典
让更多数据处理,一键完成 数据工作者的案头书 免费直播课集锦 ExcelHome出品 - VBA代码宝免费下载
用ChatGPT与VBA一键搞定Excel WPS表格从入门到精通 Excel VBA经典代码实践指南
查看: 54447|回复: 18

在WORD中如何画直角坐标系?

[复制链接]

TA的精华主题

TA的得分主题

发表于 2004-12-5 13:52 | 显示全部楼层 |阅读模式
[广告] VBA代码宝 - VBA编程加强工具 · VBA代码随查随用  · 内置多项VBA编程加强工具       ★ 免费下载 ★      ★使用手册

做了一个在WORD中画直角坐标的VBA,可是有几个问题不能解决,版主给看看

1、如何将坐标轴未端标出箭头?

2、能否标出坐标的刻度?

3、坐标原点能否自定义?即如图所示:

LPpYKFCE.rar (14.06 KB, 下载次数: 503)

在WORD中如何画直角坐标系?

在WORD中如何画直角坐标系?

TA的精华主题

TA的得分主题

发表于 2004-12-5 14:00 | 显示全部楼层
看看守柔的一个置顶帖子,偶没有测试成功。

TA的精华主题

TA的得分主题

发表于 2004-12-5 16:03 | 显示全部楼层

楼主作得不错,鼓励一下!

我的想法,请楼主看一下,能否考虑以此进行修改:

楼主采用的X/Y轴是以四个线条(不算刻度值)组合而成,直接用二条线条应该即可以作出,这样也就可以使用箭头型直线来标识方向。例:假如原点坐标选取在离页面最左上角顶端(0,0)为5CM/5CM,要求长度为X轴4CM,Y轴4CM,那么,X轴线条的LEFT=1CM,Top=5cm,WIDTH=4CM,加上预箭头位置,可以为4.5CM;y轴线条的LEFT=5CM,TOP=5-4-0.5(预留箭头位置),HIGHT=4.5CM.

然后再进行分刻度,标识刻度可以使用四个文本框(或者矩形框)进行,其宽度为四个刻度间距,如各为2CM,这样可以简化代码处理.

一些原理和代码可参考:http://club.excelhome.net/viewthread.php?tid=59709(PW:shourou)

TA的精华主题

TA的得分主题

 楼主| 发表于 2004-12-5 17:10 | 显示全部楼层
谢谢版主的回复,自己水平有限,恳请版主有时间给个例子,期待……

TA的精华主题

TA的得分主题

发表于 2004-12-7 12:54 | 显示全部楼层
[广告] VBA代码宝 - VBA编程加强工具 · VBA代码随查随用  · 内置多项VBA编程加强工具       ★ 免费下载 ★      ★使用手册

非完全版,还有一个问题未解决。(待以后有时间再说)

至于分刻度问题,我也叫不准,目前的设计应该算2分度和4分度吧?我没改叫法。

LYzYvAjT.zip (21.48 KB, 下载次数: 136)

TA的精华主题

TA的得分主题

发表于 2004-12-8 06:15 | 显示全部楼层

vbe pw:shourou

F2YxIACQ.rar (23.42 KB, 下载次数: 245)

在WORD中如何画直角坐标系?

在WORD中如何画直角坐标系?

在WORD中如何画直角坐标系?

在WORD中如何画直角坐标系?

TA的精华主题

TA的得分主题

发表于 2004-12-8 06:17 | 显示全部楼层
[广告] Excel易用宝 - 提升Excel的操作效率 · Excel / WPS表格插件       ★免费下载 ★       ★ 使用帮助

以下代码供网友学习参考:

'* +++++++++++++++++++++++++++++++++++++++

'* Created By 守柔@ExcelHome 2004-12-08 6:15:03

'仅测试于System: Windows NT Word: 10.0 Language: 2052

'^The Code CopyIn [标准模块-模块1]^'

'* --------------------------------------------------------------------------

Public BeforeShapes As Integer Sub 画坐标系() UserForm1.Show End Sub '---------------------- Sub SelAllShapes() Dim AllShapes(), ShapeCount As Integer, N As Shape, Y As Integer ShapeCount = ActiveDocument.Shapes.Count Y = 0 '定义一维上标可变数组,从0开始 ReDim AllShapes(ShapeCount - BeforeShapes - 1) With ActiveDocument For Each N In .Shapes If N.Name Like "已有图形*" = False Then AllShapes(Y) = N.Name Y = Y + 1 End If Next N With .Shapes.Range(AllShapes).Group .ZOrder msoSendToBack .Select ' .Name = "坐标系" End With End With End Sub '----------------------

'* +++++++++++++++++++++++++++++++++++++++

'* Created By 守柔@ExcelHome 2004-12-08 6:15:22

'仅测试于System: Windows NT Word: 10.0 Language: 2052

'^The Code CopyIn [用户窗体-UserForm1]^'

'* --------------------------------------------------------------------------

Private Sub CommandButton1_Click() Dim XLeft As Single, XTop As Single, YLeft As Single, YTop As Single, XLong As Single Dim YTtop As Single, YHight As Single, XLine As Shape, YLine As Shape, i As Single Dim M As Byte, MyTextbox As Shape, MyValue As Single, ModValue As Byte On Error Resume Next '忽略错误 '必要数据判断 If Me.TextBox1 = "" Or Int(Me.TextBox1) <> Me.TextBox1 * 1 Then MsgBox "无效数据!", _ vbInformation: Exit Sub If Me.TextBox2 = "" Or Int(Me.TextBox2) <> Me.TextBox2 * 1 Then MsgBox "无效数据!", _ vbInformation: Exit Sub If Me.TextBox3 = "" Or Int(Me.TextBox3) <> Me.TextBox3 * 1 Then MsgBox "无效数据!", _ vbInformation: Exit Sub If Me.TextBox3 * 1 > Me.TextBox1 * 1 Or Me.TextBox3 * 1 > Me.TextBox2 * 1 Then _ MsgBox "无效数据!", vbInformation: Exit Sub ' TextBox1为原点横坐标 , TextBox2为原点纵坐标 Application.ScreenUpdating = False XLeft = CentimetersToPoints(Me.TextBox1 - Me.TextBox3 / 2) XLong = CentimetersToPoints(Me.TextBox3 + 0.5) XTop = CentimetersToPoints(Me.TextBox2) YLeft = CentimetersToPoints(Me.TextBox1) '左边距 '顶部距离为原点纵坐标+高度/2,从下至上.则上部顶点为原点纵坐标-TextBox3/2-0.5 YTop = CentimetersToPoints(Me.TextBox2 + Me.TextBox3 / 2) YTtop = CentimetersToPoints(Me.TextBox2 - Me.TextBox3 / 2 - 0.5) YHight = CentimetersToPoints(Me.TextBox3) With ActiveDocument BeforeShapes = .Shapes.Count '获取工作之前的图形总数 If BeforeShapes >= 1 Then For i = 1 To BeforeShapes .Shapes(i).Name = "已有图形" & BeforeShapes & i '避免重复命名值出错 Next End If ' If BeforeShapes >= 1 Then MsgBox "非完全版,请删除其它图形或者在另一文档中重新建立坐标系!" _ : Exit Sub Set XLine = .Shapes.AddLine(XLeft, XTop, XLeft + XLong, XTop) Set MyTextbox = .Shapes.AddTextbox(msoTextOrientationHorizontal, XLeft + XLong - 5, XTop + 5, 20, 15) With MyTextbox '设置X轴文本框 .Line.Visible = msoFalse .TextFrame.MarginBottom = 0 .TextFrame.MarginLeft = 0 .TextFrame.MarginRight = 0 .TextFrame.MarginTop = 0 .TextFrame.TextRange.Font.Name = "Arial" .TextFrame.TextRange.Font.Size = 10 .TextFrame.TextRange = "X" End With With XLine '设置箭头形状 .Line.EndArrowheadStyle = msoArrowheadTriangle .Line.EndArrowheadLength = msoArrowheadLengthMedium .Line.EndArrowheadWidth = msoArrowheadWidthMedium End With Set YLine = .Shapes.AddLine(YLeft, YTop, YLeft, YTtop) Set MyTextbox = .Shapes.AddTextbox(msoTextOrientationHorizontal, YLeft - 20, YTtop, 15, 15) With MyTextbox '设置Y轴文本框 .Line.Visible = msoFalse .TextFrame.MarginBottom = 0 .TextFrame.MarginLeft = 0 .TextFrame.MarginRight = 0 .TextFrame.MarginTop = 0 .TextFrame.TextRange.Font.Name = "Arial" .TextFrame.TextRange.Font.Size = 10 .TextFrame.TextRange = "Y" End With With YLine '设置箭头形状 .Line.EndArrowheadStyle = msoArrowheadTriangle .Line.EndArrowheadLength = msoArrowheadLengthMedium .Line.EndArrowheadWidth = msoArrowheadWidthMedium End With Set MyTextbox = .Shapes.AddTextbox(msoTextOrientationHorizontal, _ CentimetersToPoints(Me.TextBox1) - 10, CentimetersToPoints(Me.TextBox2) - 1, 15, 15) With MyTextbox '设置原点O文本框 .Line.Visible = msoFalse .TextFrame.MarginBottom = 0 .TextFrame.MarginLeft = 0 .TextFrame.MarginRight = 0 .TextFrame.MarginTop = 0 .TextFrame.TextRange.Font.Name = "Arial" .TextFrame.TextRange.Font.Size = 8 .TextFrame.TextRange = "O" .ZOrder msoSendToBack End With If Me.OptionButton1.Value = True Then Call SelAllShapes: Exit Sub '未选刻度值退出 If Me.OptionButton2.Value = True Then MyValue = 0.5: ModValue = 2 If Me.OptionButton3.Value = True Then MyValue = 0.125: ModValue = 5 For i = 0 To Me.TextBox3 * 1 Step MyValue M = VBA.IIf(VBA.IIf(MyValue = 0.5, i * 10 Mod 10 = 0, i * 10 Mod 5 = 0), 10, 5) .Shapes.AddLine CentimetersToPoints(i + Me.TextBox1 - Me.TextBox3 / 2), XTop - M, _ CentimetersToPoints(i + Me.TextBox1 - Me.TextBox3 / 2), XTop .Shapes.AddLine YLeft, CentimetersToPoints(Me.TextBox2 + Me.TextBox3 / 2 - i), _ YLeft + M, CentimetersToPoints(Me.TextBox2 + Me.TextBox3 / 2 - i) If M = 10 And i - Me.TextBox3 / 2 <> 0 Then '逢0.5和1标识数值,忽略0值(与零点合) '对X轴刻度 Set MyTextbox = .Shapes.AddTextbox(msoTextOrientationHorizontal, _ CentimetersToPoints(i + Me.TextBox1 - Me.TextBox3 / 2) - 3, XTop + 3, 10, 10) With MyTextbox '设置刻度文本框及值 .Line.Visible = msoFalse .TextFrame.MarginBottom = 0 .TextFrame.MarginLeft = 0 .TextFrame.MarginRight = 0 .TextFrame.MarginTop = 0 .TextFrame.TextRange.Font.Name = "Arial" .TextFrame.TextRange.Font.Size = 5 .TextFrame.TextRange = i - Me.TextBox3 / 2 .ZOrder msoSendToBack End With '对Y轴刻度 Set MyTextbox = .Shapes.AddTextbox(msoTextOrientationHorizontal, YLeft + 12, _ CentimetersToPoints(Me.TextBox2 + Me.TextBox3 / 2 - i) - 8, 10, 10) With MyTextbox '设置刻度文本框及值 .Line.Visible = msoFalse .TextFrame.MarginBottom = 0 .TextFrame.MarginLeft = 0 .TextFrame.MarginRight = 0 .TextFrame.MarginTop = 0 .TextFrame.TextRange.Font.Name = "Arial" .TextFrame.TextRange.Font.Size = 5 .TextFrame.TextRange = i - Me.TextBox3 / 2 .ZOrder msoSendToBack End With End If Next Call SelAllShapes '全选图形宏(SelAllShapes) End With Application.ScreenUpdating = True End Sub '---------------------- Private Sub CommandButton2_Click() Me.TextBox1 = "" Me.TextBox2 = "" Me.TextBox3 = "" End Sub '---------------------- Private Sub CommandButton3_Click() End End Sub '---------------------- Private Sub UserForm_Activate() Me.TextBox3.SetFocus Me.CommandButton1.Default = True End Sub '---------------------- 以上代码主要修正了五楼中关于已有自选图形时后画图形的组合问题。

TA的精华主题

TA的得分主题

 楼主| 发表于 2004-12-8 07:05 | 显示全部楼层

几天有事情没来,版主就有这么多回复,而且精彩得很!非常高兴,先谢了,然后一并收下仔细研究……

呵!呵!版主就是版主!不一般!

[em17][em23]

TA的精华主题

TA的得分主题

发表于 2004-12-8 11:23 | 显示全部楼层
[广告] VBA代码宝 - VBA编程加强工具 · VBA代码随查随用  · 内置多项VBA编程加强工具       ★ 免费下载 ★      ★使用手册
佩服,送花给楼主。

TA的精华主题

TA的得分主题

发表于 2005-6-6 09:29 | 显示全部楼层
[广告] VBA代码宝 - VBA编程加强工具 · VBA代码随查随用  · 内置多项VBA编程加强工具       ★ 免费下载 ★      ★使用手册
谢谢了,我要的是坐标网格纸,我找到了一个软件Graph paper。
您需要登录后才可以回帖 登录 | 免费注册

本版积分规则

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

GMT+8, 2025-12-9 09:55 , Processed in 0.037714 second(s), 12 queries , Gzip On, MemCache On.

Powered by Discuz! X3.4

© 1999-2023 Wooffice Inc.

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

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

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