使用 VBA 创建字段时出现额外空格:{ EQ... } 而不是 {EQ...}

发布于 2024-10-29 03:55:24 字数 673 浏览 2 评论 0 原文

我使用vba在单词中创建一个重叠的字符:

a = "x"
b = "."
Selection.Fields.Add Range:=Selection.Range, Text:= _
        "EQ \o (" & a & "," & b & ")", PreserveFormatting:=False

输出是

{ EQ \o (x,.) }

产生:。正如灰色盒子可以看出的那样,角色是宽阔的。 The width can be reduced to http://img838.imageshack.us/img838/1723/ 69344761.png 通过手动更改字段,

{ EQ \o (x,.)}    or   {EQ \o (x,.)}

但是如何直接在VBA中实现?

I use VBA to create an overlapping character in Word:

a = "x"
b = "."
Selection.Fields.Add Range:=Selection.Range, Text:= _
        "EQ \o (" & a & "," & b & ")", PreserveFormatting:=False

The output is

{ EQ \o (x,.) }

which produces: http://img843.imageshack.us/img843/3783/18492133.png. As can be seen by the gray box, the character is to wide. The width can be reduced to http://img838.imageshack.us/img838/1723/69344761.png by changing the field manually to

{ EQ \o (x,.)}    or   {EQ \o (x,.)}

But how can this be achieved directly in VBA?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

爱的十字路口 2024-11-05 03:55:24

我的假设是您需要删除最终衍生品和卷曲括号之间的尾随空间。

dim x as string

dim y as string

x =“ {eq \ o(x,。)}“

y =替换(x,”}“}”,“}”)
'也可以放置”)}“替换为”)}

y成为我认为您想要的输出,

您可以使用上面显示的替换函数来完成此任务。

您的代码将成为

a = "x"
b = "."
Selection.Fields.Add Range:=Selection.Range, Text:= _
"EQ \o (" & a & "," & b & ")", PreserveFormatting:=False
Selection.Range.Text = Replace(Selection.Range.Text, ") }", ")}")

My assumption is you need to remove the trailing space between the final paranthesis and curly bracket.

Dim x As String

Dim y As String

x = "{ EQ \o (x,.) }"

y = Replace(x, " }", "}") 'Note the space for the find expression e.g. ' }'
'Could also put ") }" replace with ")}"

y becomes the output I think you desire

You can just use the replace function shown above to accomplish this task.

Your code would become

a = "x"
b = "."
Selection.Fields.Add Range:=Selection.Range, Text:= _
"EQ \o (" & a & "," & b & ")", PreserveFormatting:=False
Selection.Range.Text = Replace(Selection.Range.Text, ") }", ")}")
谢绝鈎搭 2024-11-05 03:55:24

此代码为字段 EQ 分配正确的值

 ActiveDocument.Fields.Item(numderfield).Code.Text = "EQ \o (" & a & "," & b & ")"

This code assign correct value to field EQ

 ActiveDocument.Fields.Item(numderfield).Code.Text = "EQ \o (" & a & "," & b & ")"
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文