【发布时间】:2014-04-07 04:31:55
【问题描述】:
我正在尝试让 Excel 打开 xls 以外的文件(word 文件、powerpoint 文件和 pdf 文件)。我只成功使用了 excel 文件(原因很明显)。有没有办法让excel使用默认程序打开文件。例如,如果我打开一个 .doc 文件,它应该使用 Word,但如果我打开一个 .pdf,它应该使用 Acrobat(或其他 pdf 阅读器)。我正在使用超链接。我会告诉你我到目前为止得到了什么:
我有一个列表(在本例中为 Listbox2),其中包含用于加载特定文件夹中所有文件的代码:
Private Sub UserForm_Initialize()
Dim MyFolder As String
Dim MyFile As String
Dim j As Integer
USER = TextBox99
MyFolder = "C:\Example"
MyFile = Dir(MyFolder & "\*.*")
Do While MyFile <> ""
ListBox2.AddItem MyFile
MyFile = Dir
Loop
End Sub
假设在 listbox2 中我有文件 word.doc、powerpoint.ppt、excel.xls 和 acrobat.pdf。如果我从 listbox2 中选择文件并按下带有以下代码的按钮:
Private Sub CommandButton14_Click()
Dim strFileandPath As String
strFileandPath = "C:\Example\" & UserForm1.ListBox2.Column(0)
Workbooks.Open strFileandPath
End Sub
它只会打开 excel 文件。其他的会给我一个错误。有没有办法让 Excel 使用 PC 中的默认程序打开任何类型的文件。感谢您的关注!
干杯
【问题讨论】: