vba - VBA 字对齐语法
问题描述
编辑 1: 我正在尝试使用如下所示的 Excel VBA 测试函数在 VBA 中使用右对齐的字符串(今天的日期)格式化段落。下面的这一行我认为是可以接受的语法,但我在这里或函数的其他地方出错了,因为当我打开保存的文档时日期仍然显示为左对齐:
wordLetter.Paragraphs(1).Alignment = wdAlignParagraphRight
此函数使用 Normal 模板创建新的 Word 文档,添加日期,并相对于当前 Excel 工作簿位置保存它。
否则,我知道在使用或收集方法.Paragraphs(1)
创建 Word 文档时已经存在,我只是意识到这一点。.Add
.Open
Documents
Private Function Test()
Dim objWord As Object: Set objWord = CreateObject("Word.Application")
objWord.Application.DisplayAlerts = False
objWord.Application.ScreenUpdating = False
Dim wordLetter As Object: Set wordLetter = objWord.Documents.Add
wordLetter.Range.Font.textColor.RGB = RGB(0, 0, 0)
Dim strDate As String: strDate = Format(Now(), "dddd, mmm d, yyyy")
wordLetter.Paragraphs(1).Alignment = wdAlignParagraphRight
wordLetter.Paragraphs(1).Range.text = strDate
objWord.Application.ScreenUpdating = True
savePath = ThisWorkbook.path & "\testDoc.docx"
With wordLetter
.SaveAs2 Filename:=savePath, FileFormat:=wdFormatDocumentDefault
End With
Application.DisplayAlerts = True
End Function
非常感谢任何建议。
解决方案
WordLetter.Paragraphs(1).Alignment = wdAlignParagraphRight
推荐阅读
- apache-flink - 无法对 PyFlink UDF 进行单元测试
- ftp - 为什么我在 ftp 上收到 550 权限错误
- python - 如何在python中实例化一个Optional?
- mysql - 如何用logstash解决mysql连接错误?
- python - 在 Python 中控制字符串到日期的 %y 转换
- linux - Linux 4.18.20 中 NOHZ_FULL 功能的疑惑
- angular - 表情符号的模态在 Angular 中无法正常工作
- c# - 设置器的值始终为空
- database - 我可以在生产服务器中使用基于 NoSQL 文件系统的数据库,例如 NeDB 吗?
- python - 有没有办法根据最大位数修改字符串格式?