用vb打开word excel 文件,出现提示“发现不可读取的内容”

Private Function secgoppt(Optional a As String)
Dim moPptApp As PowerPoint.Application
Dim moPptPresentation As Object

Set moPptApp = CreateObject("PowerPoint.Application")
Set moPptPresentation = moPptApp.Presentations.Open(a, , , False) '打开ppt文件
'ppt没有repair模式,如果有请补充
moPptApp.DisplayAlerts = ppAlertsNone '999
moPptPresentation.SaveAs Text5.Text
moPptPresentation.Close
moPptApp.DisplayAlerts = True
'moPptApp.DisplayAlerts = ppAlertsAll 'true
moPptApp.Quit
Set moPptApp = Nothing
Set moPptPresentation = Nothing

End Function

Private Function secgoexcel(Optional a As String)
'Dim xlApp As Excel.Application
'Dim xlWorkBook As Excel.Workbook
Dim xlApp
Dim xlWorkBook

Set xlApp = CreateObject("Excel.Application")
xlApp.Visible = False
xlApp.DisplayAlerts = False
Set xlWorkBook = xlApp.Workbooks.Open(a, , , , , , , , , , , , , , xlRepairFile)
'解决打开excel文件时提示“发现不可读取的内容”,用repair模式打开即可
xlWorkBook.SaveAs Text5.Text
'Set xlsheet = Nothing '如果前面调用了dim xlsheet as excel.worksheet则关闭时要用set xlsheet = nothing

xlWorkBook.Close
Set xlWorkBook = Nothing
xlApp.Quit
Set xlApp = Nothing '放在close和quit之前move就不会执行

End Function
Private Function secgoword(Optional a As String)
Dim WordApp
Dim Document
'.DisplayAlerts = wdAlertsNone
'.DisplayAlerts = wdAlertsAll

Set WordApp = CreateObject("word.application")
WordApp.Visible = False
WordApp.DisplayAlerts = wdAlertsNone
Set Document = WordApp.Documents.Open(a, , , , , , , , , , , , , True)

Document.SaveAs Text5.Text
Document.Close


WordApp.DisplayAlerts = wdAlertsAll
WordApp.ScreenUpdating = True
On Error Resume Next
WordApp.Quit

Set WordApp = Nothing
Set Document = Nothing

End Function

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值