在Excel中通过Visual Basic创建的Word文档中设置语言,文本方向和对齐方式 [英] Setting language, text direction and alignment in word document created by visual basic in excel

查看:370
本文介绍了在Excel中通过Visual Basic创建的Word文档中设置语言,文本方向和对齐方式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我制作了一个excel视觉基础脚本,该脚本从excel工作表中获取数据,并在单词表中为每一行生成一个段落.该文档的默认语言是希伯来语,文本从右到右对齐. 对于段落中的最后一行,我想将语言设置为英语,从左到右的方向,并向右对齐.然后,对于下一段的第一行,改回希伯来语,方向从右到左,并向右对齐. 当在段落的最后一行中用文字记录宏时,按Home键,移至末尾,单击工具栏上的图标以根据需要更改语言,方向和对齐方式,我得到:

I've made an excel visual basic script that takes data from an excel sheet, and produces a paragraph in a word sheet for each row. The default language for the document is Hebrew, with text aligned right and direction right to left. For one (the last) line in the paragraph, I want to set the language to English, the direction left to right, and the alignment right. Then, for the first line in the next paragraph change back to Hebrew, direction right to left and alignment right. When recording a macro in word when being on the last line of a paragraph, pressing home, shift end, clicking the icons on the toolbar to change language, direction and alignment as wanted, I get:

Sub test()
    Selection.HomeKey Unit:=wdLine
    Selection.EndKey Unit:=wdLine, Extend:=wdExtend
    Application.Keyboard (2057)
    Selection.LtrPara
    Selection.ParagraphFormat.Alignment = wdAlignParagraphRight
End Sub

令我惊讶的是,更改语言的记录就像是我在使用键盘一样,而不是像方向和对齐那样是对象的属性. 如何将其转换为excel visual basic?当前使用以下命令添加了相关行:

One thing that surprised me is that changing the language is recorded as if I was using the keyboard, instead of being a property of the object, just like direction and alignment. How do I translate this to excel visual basic? The line in question is currently added by using:

With f
    .Content.InsertAfter Format(a, "standard") & " x " & Format(b, "#,##0.000") & " x " & Format(c, "#,##0.000") & " / " & Format(d, "#,##0.000") & " = " & Format(e, "standard")
    .Content.InsertParagraphAfter
End With

谢谢

恩斯特(Ernst)

推荐答案

好的,我有一种解决方法,这只是部分答案.这不是Excel Visual Basic中的解决方案,而是Word中的一种解决方案:

Okay, I've got a workaround, this is only a partial answer. This is not a solution in Excel visual basic, but one in Word:

搜索所有出现的^13[!^13]@x*^13,然后更改语言,对齐方式和方向. 当将其记录为单词中的宏时,我得到以下信息:

Search for all occurences of ^13[!^13]@x*^13 and then do the language, alignment and direction change. When recording it as a macro in word, I get the following:

Sub Macro1()

Selection.Find.ClearFormatting
With Selection.Find
    .Text = "^13[!^13]@x*^13"
    .Replacement.Text = ""
    .Forward = True
    .Wrap = wdFindContinue
    .Format = False
    .MatchCase = False
    .MatchWholeWord = False
    .MatchKashida = False
    .MatchDiacritics = False
    .MatchAlefHamza = False
    .MatchControl = False
    .MatchAllWordForms = False
    .MatchSoundsLike = False
    .MatchWildcards = True
End With
Selection.LtrPara
Selection.ParagraphFormat.Alignment = wdAlignParagraphRight
Selection.Find.ClearFormatting
With Selection.Find
    .Text = "^13[!^13]@x*^13"
    .Replacement.Text = ""
    .Forward = True
    .Wrap = wdFindContinue
    .Format = False
    .MatchCase = False
    .MatchWholeWord = False
    .MatchKashida = False
    .MatchDiacritics = False
    .MatchAlefHamza = False
    .MatchControl = False
    .MatchAllWordForms = False
    .MatchSoundsLike = False
    .MatchWildcards = True
End With

结束子

但是,在新生成的Word文档上运行此命令时,这不会执行应做的事情.有什么解决方法的想法吗?顺便说一句,我可以使用excel vb在excel vb生成的文档中添加并运行word宏吗?

But when running this on a freshly generated Word document, this does not do what it's supposed to do. Any ideas for a workaround on that? Btw, can I add and run a word macro to a document generated by excel vb using excel vb?

这篇关于在Excel中通过Visual Basic创建的Word文档中设置语言,文本方向和对齐方式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆