描述:
VC6 Word AddIn 设置字体无效是什么原因?麻烦看一下
试着用VC6做了个Word2003的AddIn,要实现几个常用的字体设置功能。
关键代码如下:
struct _Font * spFont;
hr = spSelection->get_Font(&spFont);
hr = spFont->put_Name(OLESTR("方正大标宋简体"));
hr = spFont->put_Size(22);
运行没有错误,运行后字号改成了"二号",但字体设置没变过来,不知那里出了问题?
同样的功能对应的宏代码是:
Selection.Font.Name = "方正大标宋简体"
Selection.Font.Size = 22
另,设置文档的默认字体时,也就是通过“页面设置->文档网格->字体设置”设置字体的宏代码为:
With ActiveDocument.Styles(wdStyleNormal).Font
.NameFarEast = "方正仿宋简体"
.NameAscii = "Times New Roman"
.NameOther = "Times New Roman"
.Name = "Times New Roman"
.Size = 16
如何转为VC代码呢?请指教,多谢!
解决方案1:
展开就是这样子
ActiveDocument.Styles(wdStyleNormal).Font
ActiveDocument.Styles(wdStyleNormal).Font.NameFarEast = "方正仿宋简体"
ActiveDocument.Styles(wdStyleNormal).Font.NameAscii = "Times New Roman"
ActiveDocument.Styles(wdStyleNormal).Font.NameOther = "Times New Roman"
ActiveDocument.Styles(wdStyleNormal).Font.Name = "Times New Roman"
ActiveDocument.Styles(wdStyleNormal).Font.Size = 16
其中Styles这个属性有参数,剩下的几乎也都是属性,按着属性赋值应该就没问题了