|
[广告] VBA代码宝 - VBA编程加强工具 · VBA代码随查随用 · 内置多项VBA编程加强工具 ★ 免费下载 ★ ★ 使用手册★
各位前辈:
我在excel中用代码操作word,在有打开其他word文档的时候,运行代码会出现“此文件正由另一应用程序或用户使用”的提示,在没由打开其他word文档的情况下运行代码就没有此问题,请教这个问题怎么解决!
- Sub 选型输出()
- On Error Resume Next
- Dim wordapp As Object
- Dim lujing As String
- Dim newname As String
- Dim newpath As String
- Application.ScreenUpdating = False
- Set wordapp = CreateObject("word.application")
- newname = Worksheets("选型表").Cells(35, 4).Value
- lujing = ThisWorkbook.Path
- FileCopy lujing & "\MOBA\ZG.docx", lujing & "\选型输出" & newname & ".docx"
- newpath = lujing & "\选型输出" & newname & ".docx"
- With wordapp
- .Visible = False
- With .Documents.Open(newpath)
- Select Case Worksheets("选型表").Cells(2, 4).Value
- Case 条件1
- .Bookmarks("MODLE").Range = Worksheets("选型表").Cells(35, 4).Value
- ..........
- .Close True
- Case 条件2
- ..........
- .Close True
- Case 条件3
- ..........
- .Close True
- End Select
- End With
- .Quit
- End With
- Set wordapp = Nothing
- Application.ScreenUpdating = True
- End Sub
复制代码
|
|