作者:乔山办公网日期:
返回目录:excel表格制作
Subtest()DimFileName,xlsNameAsStringFileName=Application.GetOpenFilename("Excel文件(*.xls),*.xls")xlsName=Mid(FileName,InStrRev(FileName,"\")+1,100)MsgBoxxlsNameEndSub
Const fName As String = "MyExcelFile.xls"
Sub testFileOpen()
Dim xApp As Application
Set xApp = CreateObject("Excel.Application")
xApp.DisplayAlerts = False
On Error GoTo FileError
xApp.Workbooks.Open Filename:=ThisWorkbook.Path & "\" & fName, notify:=False, ReadOnly:=False
If xApp.ActiveWorkbook.ReadOnly = True Then
MsgBox "File is already opened!来"
Else
MsgBox "File is not opened!"
End If
GoTo QuitSub
FileError:
MsgBox "File is not exist"
QuitSub:
xApp.Quit
End Sub
附件自可下载知参考道
Sub 打开文件()
Dim name
name = Environ("username") '获取电脑用户名zhidao
If name = "Li.li" Then '判断用户名是否为"li.li"
Workbooks.Open "D:\1\1.xlsx" '条件成立打开指定文专件名
Else
MsgBox "A" '条件不成立,属弹出对话框
End If
End Sub
Sub aa()
Dim curBK As Workbook
Dim fromBk As Workbook
Dim bk As Workbook
Set curBK = ThisWorkbook '把当前工作薄zd赋值给一个对象变量
For Each bk In Application.Workbooks
If bk.Name = "B.xlsx" Then
Set fromBk = bk
Exit For
End If
Next
If fromBk Is Nothing Then
MsgBox "B.xlsx没有在当前EXCEL进程中打开版" '如果B文件权没有打开则退出程序
Exit Sub
End If
'如果B文件已经打开,直接进行操作
curBK.Worksheets("A文件中的A工作表").Range("A1") = fromBk.Worksheets("B文件中的B工作表").Range("A1")
End Sub