高手救我!!!
用VC写了个Activex,并写了个MFC应用程序,并写了个VBA脚本.工作基本正常(这是最可恨的),有一个很不明白的地方,该VBA插入在Word中工作完全正确,能正确判断各个元素,但单独保存为一个TXT脚本后在应用程序中调用,能工作,却只有一部分能正确判断,有些地方就判断不出来!
请教各位,原因何在????如何解决?????
用VC写了个Activex,并写了个MFC应用程序,并写了个VBA脚本.工作基本正常(这是最可恨的),有一个很不明白的地方,该VBA插入在Word中工作完全正确,能正确判断各个元素,但单独保存为一个TXT脚本后在应用程序中调用,能工作,却只有一部分能正确判断,有些地方就判断不出来!
请教各位,原因何在????如何解决?????
解决方案 »
- 串口通讯中执行CloseHandle时死机
- [急切求助]如何使用SAPI实现批量文本转换成wav语音(现在只实现转换一条)
- 如何将int按如下格式转存到char?谢谢
- 关于8.3文件名的奇怪问题?怎么一会简写,一会全称。
- 请教打开应用程序实例的问题
- MFC程序是先进FRAME的ONCREATE还是APP的INITINSTANCE
- 高分请教:如何做一个上网限制的程序
- 各位兄弟帮忙,急!!对CListCtrl排序后,再重新插入数据显示错误!!
- 如何覆盖文本文件中的一行。(在线等待)。
- 用GetPixel提取位图RGB之后 ,用什么函数将提取值显示在列表框里?谢谢俄!
- 在客户端的工程中将COM的idl文件加入后,为什么编译会出错。
- vc的图形编程中,为何不能单步的同时看到客户区所画图形的变化?而cb里面可以的阿。
Dim wdShapeCenter
Dim wdWrapTight
Dim wdColorGray20
Dim wdColorRed
Dim wdLineSpace1pt5
Dim wdAlignParagraphCenter
wdShapeCenter = -999995
wdWrapTight = 1
wdColorGray20 = 13421772
wdColorRed = 255
wdLineSpace1pt5 = 1
wdAlignParagraphCenter = 1
Dim wrd
Dim score
Set wrd = Application On Error Resume Next
score = 0# Set wordDocument = ThisDocument
If Err.Number <> 0 Then
TextBox2.Text = TextBox2.Text & "没有打开 " & FileName & " ,无法进行判分操作"
Err.Clear
'' Document.SetExamResult 1.1, score
Exit Sub
End If
para_count = wordDocument.Paragraphs.Count ''''段落查找
i_title = 0
p1 = 0
p2 = 0
p3 = 0
p4 = 0
myText1 = "在本月初于拉斯维加斯举行的计算机商业博览会上"
myText2 = "但对于一些分析人士而言,"
myText3 = "一位发言人表示,去年首次推出这种产品"
myText4 = "电脑是为了将笔记本电脑和PDA" para_count = wordDocument.Paragraphs.Count
For i = 1 To para_count
If Len(wordDocument.Paragraphs(i).Range.Text) > 4 Then
If i_title = 0 Then
i_title = i
End If
End If If InStr(wordDocument.Paragraphs(i).Range.Text, myText1) <> 0 Then
p1 = i
ElseIf InStr(wordDocument.Paragraphs(i).Range.Text, myText2) <> 0 Then
p2 = i
ElseIf InStr(wordDocument.Paragraphs(i).Range.Text, myText3) <> 0 Then
p3 = i
ElseIf InStr(wordDocument.Paragraphs(i).Range.Text, myText4) <> 0 Then
p4 = i
End If
Next
'step1: 添加标题 (居中对齐)
flag1 = False If i_title > 0 And i_title < p1 Then
With wordDocument.Paragraphs(i_title).Range
If .Text = "写字板电脑" & vbCr _
And .ParagraphFormat.Alignment = wdAlignParagraphCenter Then
If Err.Number <> 0 Then
Err.Clear
Else
flag1 = True
End If
End If
End With
End If
score = score + 3
TextBox2.Text = TextBox2.Text & "添加标题正确"
'' Document.SetStepValue step_No, 2, True, 3, "添加标题正确"
Else
TextBox2.Text = TextBox2.Text & "添加标题错误"
'' Document.SetStepValue step_No, 2, False, 3, "添加标题错误"
End If'step2: 标题格式设置 (黑体,三号, 红色)
flag2 = False
If flag1 = True Then
With wordDocument.Paragraphs(i_title).Range
If InStr(.Font.NameFarEast, "黑体") <> 0 And .Font.Size = 16 _
And .Font.Color = wdColorRed Then
If Err.Number <> 0 Then
Err.Clear
Else
flag2 = True
End If
End If
End With
End If
' [_描述信息]
step_No = 2 '第几步 If flag2 = True Then
score = score + 3
TextBox2.Text = TextBox2.Text & "标题格式设置正确"
'' Document.SetStepValue step_No, 2, True, 3, "标题格式设置正确"
Else
TextBox2.Text = TextBox2.Text & "标题格式设置错误"
'' Document.SetStepValue step_No, 2, False, 3, "标题格式设置错误"
End If'step3: 段落行距设置 (1.5倍行距)
flag3 = False
If para_count > 1 Then
flag3 = True
End If
For i = i_title + 1 To para_count
With wordDocument.Paragraphs(i)
If Len(.Range.Text) > 1 Then
If .LineSpacingRule <> wdLineSpace1pt5 Then
If Err.Number <> 0 Then
Err.Clear
End If
flag3 = False
Exit For
End If
End If
End With
Next
' [_描述信息]
step_No = 3 '第几步 If flag3 = True Then
score = score + 3
TextBox2.Text = TextBox2.Text & "段落行距设置正确"
'' Document.SetStepValue step_No, 2, True, 3, "段落行距设置正确"
Else
TextBox2.Text = TextBox2.Text & "段落行距设置错误"
'' Document.SetStepValue step_No, 2, False, 3, "段落行距设置错误"
End If'step4: 第二段分栏 (二栏,栏宽相等,间距2字符)
' [段落分栏]
flag4 = False
If p2 > 0 Then
With wordDocument.Paragraphs(p2).Range.PageSetup
Spacing = 10.5 * 2 '10.5为1个字符的宽度
If .TextColumns.Count = 2 _
And .TextColumns(1).Width = .TextColumns(2).Width _
And Abs(.TextColumns(1).SpaceAfter - Spacing) < 1 Then
If Err.Number <> 0 Then
Err.Clear
Else
flag4 = True
End If
End If
End With
End If
'[_描述信息]
step_No = 4 '第几步 If flag4 = True Then
score = score + 3
TextBox2.Text = TextBox2.Text & "第二段分栏正确"
'' Document.SetStepValue step_No, 2, True, 3, "第二段分栏正确"
Else
TextBox2.Text = TextBox2.Text & "第二段分栏错误"
'' Document.SetStepValue step_No, 2, False, 3, "第二段分栏错误"
End If'step5: 将最后两段合并
flag5 = False
If p4 > 0 Then
If InStr(wordDocument.Paragraphs(p4).Range.Text, "虽然这种电脑的问世可能不会导致笔记本电脑的消亡") <> 0 Then
If Err.Number <> 0 Then
Err.Clear
Else
flag5 = True
End If
End If
End If
' [_描述信息]
step_No = 5 '第几步 If flag5 = True Then
score = score + 3
TextBox2.Text = TextBox2.Text & "将最后两段合并正确"
'' Document.SetStepValue step_No, 2, True, 3, "将最后两段合并正确"
Else
TextBox2.Text = TextBox2.Text & "将最后两段合并错误"
'' Document.SetStepValue step_No, 2, False, 3, "将最后两段合并错误"
End If'step6: 查找替换
flag6 = False
'[查找替换]
With wordDocument.Content.Find
If Err.Number <> 0 Then
Err.Clear
Else
.MatchCase = True
.Wrap = 0
.Text = "微软"
If .Execute = False Then
flag6 = True
End If
If flag6 = True _
And wordDocument.Content.Find.Execute("MicroSoft") = True Then
Count = 0
.Text = "MicroSoft"
.Forward = True
Do While .Execute = True
Count = Count + 1
Loop
If Count = 7 Then
flag6 = True
Else
flag6 = False
End If
Else
flag6 = False
End If
End If
End With'[_描述信息]
step_No = 6 '第几步 If flag6 = True Then
score = score + 3
TextBox2.Text = TextBox2.Text & "查找替换正确"
'' Document.SetStepValue step_No, 2, True, 3, "查找替换正确"
Else
TextBox2.Text = TextBox2.Text & "查找替换错误"
'' Document.SetStepValue step_No, 2, False, 3, "查找替换错误"
End If'step7: 第一段底纹设置 (20%-灰)
flag7 = False
If p1 > 0 Then
If wordDocument.Paragraphs(p1).Range.Shading.BackgroundPatternColor = wdColorGray20 Then
If Err.Number <> 0 Then
Err.Number = 0
Else
flag7 = True
End If
End If
End If
'[_描述信息]
step_No = 7 '第几步 If flag7 = True Then
score = score + 3
TextBox2.Text = TextBox2.Text & "第一段底纹设置正确"
'' Document.SetStepValue step_No, 2, True, 3, "第一段底纹设置正确"
Else
TextBox2.Text = TextBox2.Text & "第一段底纹设置错误"
'' Document.SetStepValue step_No, 2, False, 3, "第一段底纹设置错误"
End If'step8: 插入图片 (紧密型,居中对齐)
flag8 = False
If wordDocument.Shapes.Count = 1 And p2 > 0 And p3 > 0 Then
Set myRange = wordDocument.Range(wordDocument.Paragraphs(p2).Range.Start, wordDocument.Paragraphs(p3).Range.End)
With wordDocument.Shapes(1)
If .Anchor.InRange(myRange) _
And .WrapFormat.Type = wdWrapTight _
And .Left = wdShapeCenter Then
If Err.Number <> 0 Then
Err.Number = 0
Else
flag8 = True
End If
End If
End With
End If
'[_描述信息]
step_No = 8 '第几步 If flag8 = True Then
score = score + 3
TextBox2.Text = TextBox2.Text & "插入图片正确"
'' Document.SetStepValue step_No, 2, True, 3, "插入图片正确"
Else
TextBox2.Text = TextBox2.Text & "插入图片错误"
'' Document.SetStepValue step_No, 2, False, 3, "插入图片错误"
End If
'[设置分数]
'' Document.SetExamResult 1.1, score '设置分数
TextBox1.Text = score
End Sub
好久没有做vb咯~~接分