excel - 从 Excel 写入 Word
问题描述
在 Excel 宏中,我将工作表行的内容写入 Word .docx。实际的写作指导是
objselection.TypeText (textB)
这以无可争议的格式写入。
我的问题是:我可以控制字体吗?例如,我想用斜体字书写。
解决方案
Sub Skeleton()
'
Dim wkb1 As Workbook
Dim objApplication As Object
'
file_path = "E:\TUSHINO COMPANY\AAAB FIND NEW PROJECT\Breadline 2021\Customer Documents\"
sfulname = file_path & "Experimental Doc"
'
' CREATE THE WORD OBJECT
'
Set objWord = CreateObject("Word.application")
objWord.Visible = True
'
' ADD A DOCUMENT TO THE WORD OBJECT
'
Set objDoc = objWord.Documents.Add
'
Set objselection = objWord.Selection
'
' I was surprised that this is not " = objDoc.Selection"
'
' In production there would be code extracting stuff
' from the worksheet ready to write on the word document
'
textA = " This is the first write"
With objselection
.Font.Size = 12
.TypeText (textA) ' Top of the page heading
End With
'
objDoc.SaveAs (sfulname)
objWord.Application.Quit ' This is needed to close the document
Set objWord = Nothing
'
998 xx = 0
'
ay = "Finished"
MsgBox ay
'
999 xx = 0
'
End Sub
推荐阅读
- python - 用folium制作等值线图
- vb.net - System.ArgumentException:至少一个对象必须实现 IComparable
- git - Git 在 Docker 容器中运行太慢
- android - RecyclerView:在可见性之前加载
- symfony4 - symfony datetime 无法映射到实体
- node.js - Node.js child_process.execFile() 不适用于自己的 .exe
- c++ - C ++中文本文件的问题
- php - 使用工具扫描时对过度使用的网络服务器进行故障排除
- ios - 将核心数据对象附加到数组中
- algorithm - 计算键盘序列可能单词的有效算法,无需 T9