vba代码在vb6中运行没有报错但是只显示了个窗体出来
代码的味道 2017-08-07 10:07:06 我想把vba代码打包成exe文件,代码编译通过了但是运行的时候只显示了窗体没有运行代码,求大神们看看怎么回事
Sub word_format()
'新建打开对话框
Dim mydialog As FileDialog
Dim myselecteditem As Variant
Dim doc As Document
Dim yijititle As Paragraph
Dim erjititle As Paragraph
Dim mypicture As Shape
Dim myyemei As Range
Dim myyema As Range
Set mydialog = Application.FileDialog(msoFileDialogOpen) '定义文件选取对话框
With mydialog '设置对话框
.AllowMultiSelect = True '允许多选
.Filters.Clear '清除文件筛选条件
.Filters.Add "文本文件", "*.docx", 1 '添加文件的格式要求
If .Show = -1 Then '单击“确定”按钮,返回-1
Application.ScreenUpdating = False '关闭屏幕刷新
For Each myselecteditem In .SelectedItems
Set doc = Documents.Open(FileName:=myselecteditem, Visible:=False)
With doc '设置文档格式
With .PageSetup '页面设置
.Orientation = wdOrientPortrait '页面方向为纵向
.TopMargin = CentimetersToPoints(2.3) '上边距
.LeftMargin = CentimetersToPoints(2.3) '左边距
.RightMargin = CentimetersToPoints(2.3) '右边距
.BottomMargin = CentimetersToPoints(2.3) '下边距
.HeaderDistance = CentimetersToPoints(1.2) '页眉
.FooterDistance = CentimetersToPoints(1.2) '页脚
End With
With .Content.ParagraphFormat '设置段落格式
.LeftIndent = CentimetersToPoints(0) '左缩进0
.RightIndent = CentimetersToPoints(0) '右缩进0
.LineSpacingRule = wdLineSpaceMultiple
.LineSpacing = LinesToPoints(1.72) '行间距24磅
.Alignment = wdAlignParagraphJustify '对齐方式为两端对齐
.LineUnitAfter = 0 '段后0
.LineUnitBefore = 0 '段前0
.SpaceAfter = 0
.SpaceBefore = 0
.CharacterUnitFirstLineIndent = 2 '首行缩进2字符
End With
With .Content
With .Font '字符格式设置
.NameFarEast = "微软雅黑" '中文字体
.NameAscii = "Times New Roman" '西文字体
.Size = 10.5 '字体大小
.Color = wdColorBlack '字体颜色
End With
With .Paragraphs.First '设置首行题目字体格式
.Range.Font.Size = 22
.Range.Font.NameFarEast = "楷体"
.Range.Font.NameAscii = "Times New Roman"
.Range.Font.Color = wdColorBlack
.Range.Font.Bold = True
.Alignment = wdAlignParagraphCenter
End With
For Each yijititle In .Paragraphs '设置一级标题格式
If yijititle.OutlineLevel = wdOutlineLevel1 Then
With yijititle
.Range.Font.NameFarEast = "幼圆"
.Range.Font.NameAscii = "Times New Roman"
.Range.Font.Size = 18
.Range.Font.Bold = True
.Range.Font.Color = wdColorBlack
.CharacterUnitFirstLineIndent = 0
End With
End If
Next
For Each erjititle In .Paragraphs '设置二级标题格式
If erjititle.OutlineLevel = wdOutlineLevel2 Then
With erjititle
.Range.Font.NameFarEast = "幼圆"
.Range.Font.NameAscii = "Times New Roman"
.Range.Font.Size = 14
.Range.Font.Bold = True
.Range.Font.Color = wdColorBlack
.CharacterUnitFirstLineIndent = 0
End With
End If
Next
End With
Set myyemei = .Sections(1).Headers(wdHeaderFooterPrimary).Range '添加页眉
With myyemei
.Text = "华星在线教育"
.Font.NameFarEast = "楷体"
.Font.Size = 9
.Font.Color = wdColorBlueGray
.Paragraphs.Alignment = wdAlignParagraphCenter
.ParagraphFormat.Borders(3).LineStyle = wdLineStyleNone
End With
Set myyema = .Sections(1).Footers(wdHeaderFooterPrimary).Range '添加页码 第几页
With myyema
.Font.Size = 9
.Font.Name = "Times New Roman"
.Text = "—第 "
.Collapse wdCollapseEnd
.Fields.Add myyema, wdFieldEmpty, "Page"
Set myyema = .Sections(1).Footers(wdHeaderFooterPrimary).Range
myyema.Collapse wdCollapseEnd
myyema.Text = " 页—"
.Fields.Update
.ParagraphFormat.Alignment = wdAlignParagraphCenter
End With
' With .Sections(1) '只添加页码数字
'
' .Footers(wdHeaderFooterPrimary).PageNumbers.Add PageNumberAlignment:=wdAlignPageNumberCenter, FirstPage:=True
'
' End With
.Close True
End With '文档doc设置完成
Next
Application.ScreenUpdating = True
MsgBox "格式化文档操作设置完毕!", vbInformation
Else
MsgBox "已取消操作!", vbInformation '“取消”按钮
End If
End With
End Sub