网上下载的一个doc转docx的宏文件,为什么运行错误总是出错,请高手帮忙看一下什么原因?

Sub doctodocx()
Dim sEveryFile As String
Dim sSourcePath As String
Dim sNewSavePath As String
Dim CurDoc As Object
sSourcePath = "E:\DOC文件\"
sEveryFile = Dir(sSourcePath & "*.doc")
Do While sEveryFile <> ""
Set CurDoc = Documents.Open(sSourcePath & sEveryFile, , , , , , , , , , , msoFalse)
CurDoc.Convert
sNewSavePath = VBA.Strings.Replace(sSourcePath & "\DOCX文件\" & sEveryFile, ".doc", ".docx")
CurDoc.SaveAs2 sNewSavePath, wdFormatDocumentDefault
CurDoc.Close SaveChanges:=False
sEveryFile = Dir
Loop
Set CurDoc = Nothing
End Sub

Sub 宏1()
Dim sEveryFile As String
Dim sSourcePath As String
Dim sNewSavePath As String
Dim CurDoc As Object
sSourcePath = "d:\ctest\"
sEveryFile = Dir(sSourcePath & "*.doc")
Do While sEveryFile <> ""
Set CurDoc = Documents.Open(sSourcePath & sEveryFile, , , , , , , , , , , msoFalse)
CurDoc.Convert
sNewSavePath = VBA.Strings.Replace(sSourcePath & "\DOCX文件\" & sEveryFile, ".doc", ".docx")
CurDoc.SaveAs sNewSavePath, wdFormatDocumentDefault
CurDoc.Close SaveChanges:=False
sEveryFile = Dir
Loop
Set CurDoc = Nothing
End Sub

只修正了一个很小很小的问题,word2007上测试通过。有几个细节必须注意:

1、doc文件所在目录d:\ctest可以自行修改。但其下的“DOCX文件”
目录必须手工建立,代码不会自动创建这个目录。以这个例子而言就是必须手工建立d:\ctest\DOCX目录

2、为保证顺利运行,如果打开了word,请先关闭。重新打开后,用alt + f8键调出宏,运行就没有任何问题了。

温馨提示:答案为网友推荐,仅供参考
第1个回答  2019-04-06
你的文件是放在E:\DOC文件\文件夹下吗,如果不是就要修改这个与你的文件所在文件夹相同。
第2个回答  2019-04-06
1、库文件不支持
2、你可以直接用office2010及以后版本另存为docx就行,或者兼容保存为doc随意
3、doc的话直接改docx扩展名也可以在高级版本打开的
望采纳追问

谢谢解答,主要是有很多文档需要转换,想批量进行。
我是在网上下载的,对此一窍不通,能否帮忙修改一下,万分感谢!
我用的是office2007,是不是用2010就可以了?

追答

对,直接升级Office就行了

本回答被网友采纳
第3个回答  2019-04-06
可以直接用office2010及以后版本另存为docx就行,或者兼容保存为doc
第4个回答  2019-04-06
不建议使用宏文件,建议您下载一个office补丁就可以解决您的这个问题。
而且去微软官方网站上就能下载,安全可靠。