用户登录
用户注册

分享至

vbawordfont

  • 作者: 许诺ve誓言
  • 来源: 51数据库
  • 2020-04-21

1.VBA for Word怎么设置字体的格式

以下代码为通过VBA代码来设置Word字体的各种格式。

WApp.Selection.Font.NameFarEast = "华文中宋";

WApp.Selection.Font.NameAscii = "Times New Roman";

WApp.Selection.Font.NameOther = "Times New Roman";

WApp.Selection.Font.Name = "宋体";

WApp.Selection.Font.Size = float.Parse("14");

WApp.Selection.Font.Bold = 0;

WApp.Selection.Font.Italic = 0;

WApp.Selection.Font.Underline = Microsoft.Office.Interop.Word.WdUnderline.wdUnderlineNone;

WApp.Selection.Font.UnderlineColor = Microsoft.Office.Interop.Word.WdColor.wdColorAutomatic;

WApp.Selection.Font.StrikeThrough =0;//删除线

WApp.Selection.Font.DoubleStrikeThrough = 0;//双删除线

WApp.Selection.Font.Outline =0;//空心

WApp.Selection.Font.Emboss = 0;//阳文

WApp.Selection.Font.Shadow = 0;//阴影

WApp.Selection.Font.Hidden = 0;//隐藏文字

WApp.Selection.Font.SmallCaps = 0;//小型大写字母

WApp.Selection.Font.AllCaps = 0;//全部大写字母

WApp.Selection.Font.Color = Microsoft.Office.Interop.Word.WdColor.wdColorAutomatic;

WApp.Selection.Font.Engrave = 0;//阴文

WApp.Selection.Font.Superscript = 0;//上标

WApp.Selection.Font.Subscript = 0;//下标

WApp.Selection.Font.Spacing = float.Parse("0");//字符间距

WApp.Selection.Font.Scaling = 100;//字符缩放

WApp.Selection.Font.Position = 0;//位置

WApp.Selection.Font.Kerning = float.Parse("1");//字体间距调整

WApp.Selection.Font.Animation = Microsoft.Office.Interop.Word.WdAnimation.wdAnimationNone;//文字效果

WApp.Selection.Font.DisableCharacterSpaceGrid =false;

WApp.Selection.Font.EmphasisMark = Microsoft.Office.Interop.Word.WdEmphasisMark.wdEmphasisMarkNone;

2.如何用word vba实现页面设置里的字体设置

With Selection.Font

.NameFarEast = "宋体"

.NameAscii = "Times New Roman"

.NameOther = "Times New Roman"

.Name = "Times New Roman"

.Size = 12

.Bold = False

.Italic = False

.Underline = wdUnderlineNone

.UnderlineColor = wdColorAutomatic

.StrikeThrough = False

.DoubleStrikeThrough = False

.Outline = False

.Emboss = False

.Shadow = False

.Hidden = False

.SmallCaps = False

.AllCaps = False

.Color = wdColorAutomatic

.Engrave = False

.Superscript = False

.Subscript = False

.Spacing = 0

.Scaling = 100

.Position = 0

.Kerning = 1

.Animation = wdAnimationNone

.DisableCharacterSpaceGrid = False

.EmphasisMark = wdEmphasisMarkNone

End With

补充:

wdStyleNormal=-1,试试With ActiveDocument.Styles(-1).Font

3.vba word 中 怎么得到当前文档中所有字体的名称啊

给你代码吧:

Sub a()

Dim str As String

For Each c In ThisDocument.Characters

If InStr(str, c.Font.Name) = 0 And Len(c.Font.Name) > 0 Then

str = str & c.Font.Name & ","

End If

Next

MsgBox UBound(Split(Left(str, Len(str) - 1), ",")) + 1 & "种字体,分别是" & vbCrLf & Left(str, Len(str) - 1)

End Sub

4.Word VBA中,用什么语句来调用内置字体对话框

你按F1进入帮助,查找Dialogs,有解释和例子。

所有的Dialogs可以用如下方法获得。在VBA界面,点菜单的插入,模块,粘贴如下代码:

Sub x()

Dim xDlg As Dialog

Dim xStr As String

For Each xDlg In Application.Dialogs

xStr = xStr & Chr(13) & xDlg.CommandName

Next

Selection.TypeText xStr

End Sub

按F5运行此宏,得到了所有的内置对话框。

然后可以用

Sub xxxx()

Application.Dialogs(wdDialogFormatDefineStyleLang).Show

End Sub

粗体部分就是上面的那些名字,改为任意一个,运行就可以了。

没有表样式的。

5.如何在Excel VBA 中读写word文档 步骤

参考这个:

Sub ExcelToWord() ' 利用Word程序创建文本文件

Dim WordApp As Object

Dim Records As Integer, i As Integer

Dim Region As String, SalesAmt As String, SalesNum As String, strTitle As String

Set WordApp = CreateObject("Word.Application") '创建word对象

Records = Application.CountA(Sheets("sheet1").Range("A:A")) 'A列数据个数

WordApp.Documents.Add '新建文档

'写Title

strTitle = Cells(1, 5)

With WordApp.Selection

.Font.Size = 28

.ParagraphFormat.Alignment = 1 '左对齐0 居中1 右对齐2

.Font.Bold = True

.TypeText Text:=strTitle

.TypeParagraph

End With

'写内容

For i = 1 To Records

'Region = Data.Cells(i, 1).Value '将第一列某行的值赋值给变量

Region = Cells(i, 1)

'SalesNum = Data.Cells(i, 2).Value '获取该行B列数据

SalesNum = Cells(i, 2)

'SalesAmt = Data.Cells(i, 3).Value '获取该行C列数据

SalesAmt = Cells(i, 3)

With WordApp.Selection

.Font.Size = 14 '设置字体字号

.Font.Bold = True '字体粗

.ParagraphFormat.Alignment = 0 '设置对齐

.TypeText Text:=Region & SalesNum

.TypeParagraph

.Font.Size = 12 '设置字体

.ParagraphFormat.Alignment = 0 '设置对齐

.Font.Bold = False '字体不加粗

.TypeText Text:=vbTab & SalesAmt

.TypeParagraph '回车

.TypeParagraph '回车

End With

Next i

WordApp.ActiveDocument.SaveAs Filename:="AAA" '保存文件

WordApp.Quit '退出程序

Set WordApp = Nothing '清空

MsgBox "文件保存在我的文档底下的AAA文件"

End Sub

转载请注明出处51数据库 » vbawordfont

软件
前端设计
程序设计
Java相关