用VB访问以后的WORD文件,并在WORD文件页眉上插入一个图片
以下是全部程序。问题:为啥程序没有报错,但是结果却没有插入图片到页眉中呢?
Dim WordApp As Word.Application
Dim WordDoc As Word.Document
Sub insertpic()'这个是在WORD里头录制的宏代码
If ActiveWindow.View.SplitSpecial <> wdPaneNone Then
ActiveWindow.Panes(2).Close
End If
If ActiveWindow.ActivePane.View.Type = wdNormalView Or ActiveWindow. _
ActivePane.View.Type = wdOutlineView Then
ActiveWindow.ActivePane.View.Type = wdPrintView
End If
ActiveWindow.ActivePane.View.SeekView = wdSeekCurrentPageHeader
Selection.InlineShapes.AddPicture FileName:="E:\编程\开发的软件(test)\test.jpg", _
LinkToFile:=False, SaveWithDocument:=True
Selection.ParagraphFormat.Alignment = wdAlignParagraphLeft
ActiveWindow.ActivePane.View.SeekView = wdSeekMainDocument
End Sub
Private Sub Command1_Click()'这个是程序,实现打开制定的word文件,并且在上面调用宏,然后保存,关闭的代码。
Set WordApp = CreateObject("Word.Application")
Set WordDoc = WordApp.Documents.Open("E:\编程\尝试\1.doc")
Call insertpic
WordDoc.Save
WordDoc.Close
WordApp.Application.Quit
End Sub
[解决办法]
程序没问题,请检查路径开发的软件(test) 是否正确。
你得代码是在VB6里还是在WORD里执行?