我测试代码没问题。你的报什么错?
要注意,你文件夹下,要全部是doc文件,不能有别的文件,不然肯定报错。
或者,你判断一下后缀是不是doc文件,如
Dim dlg As New FolderBrowserDialog
If dlg.ShowDialog = DialogResult.Ok Then
For Each File As String In FileSys.GetFiles(dlg.SelectedPath)
If file.EndsWith(".doc") OrElse file.EndsWith(".docx") Then
Dim rs As String = File.SubString(0,File.Length-4)
Dim tg As String = rs & ".pdf"
Dim app As New MSWord.Application
try
Dim doc = app.Documents.Open(File)
doc.ExportAsFixedFormat(tg, MSWord.WdExportFormat.wdExportFormatPDF)
doc.saved = True
app.Quit
catch ex As exception
msgbox(ex.message)
app.Quit
End try
End If
Next
End If