有关Excel VBA得问题,高手们帮个忙

2024-12-26 22:06:28
推荐回答(3个)
回答1:

假设两个文件都存放在同一个文件夹下面:
[B1] = "文件2.xls"

Sub 打开B1文件()
Dim openFile_path As String
Dim openFile_name As String
'获取需要打开的文件名,和路径
openFile_path = ThisWorkbook.Path
openFile_name = [B1]
'显示一下文件名是否正确,可以注释掉
MsgBox [B1]
'其实就这么一句话的事..
Workbooks.Open openFile_path & "\" & [B1]
End Sub

然后自己设置一个按钮加宏

回答2:

A1写要打开文件的路径:例如====》D:\YourFile\Me\
B1写要打开的文件名: 例如 ===》MyFriend.xls
在VBA上定义, Dim StrPath As String :Dim StrFilename As String
赋值, StrPath=cells(1,1) : StrFilename =StrPath+cells(1,2)
打开文件: Workbooks.Open Filename:=StrFileName

可以啦!五步而已。另加按钮不算!

jhzhujulius@163.com

回答3:

'打开文件用下面的语句
Private Sub CommandButton1_Click()
Workbooks.Open Sheets(1).Cells(2, 2).Value & ".xls"
End Sub
'选择文件用下面的语句
Private Sub CommandButton1_Click()
Workbooks(Sheets(1).Cells(2, 2).Value & ".xls").Activate
End Sub