|
本帖最后由 高绪山 于 2011-12-11 19:50 编辑
对不起,我没说明白。是这样:
1.我有一个核算材料的程序,都要使用“材料定额库”,例如,材料定额库.xls 。该文件是共享的,大家都用;
2.在我的主程序打开时,要判定“材料定额库.xls” 工作簿是否应经打开。如果,未打开就打开。已经打开直接激活即可;
3.为了不引起操作人员的混乱,我想将“材料定额库.xls” 工作表隐含在后台进行读写。
4.基本情况就是这样。下面的程序。用: If UCase(Trim(WB.Name)) = UCase(DingEName) Then
和set wb1 = Workbooks(DingEPath & DingEName) If wb1 Is Nothing Then 进行判断,都提示“文件已经打开,是否重新打开?”提示。
5.只有在“材料定额库.xls”可见时,用:“If UCase(Trim(WB.Name)) = UCase(DingEName) Then “ 可以判断,直接激活。
部分程序如下:
If UCase(Sheets("程序专用").Cells(6, "B")) = "当前工作目录" Or Trim(VBA.UCase(Sheets("程序专用").Cells(6, "B"))) = "" Then
DingEPath = ActiveWorkbook.Path & "\"
Else
DingEPath = Trim(Sheets("程序专用").Cells(6, "B"))
End If
DingEName = Trim(Sheets("程序专用").Cells(7, "B"))
bOpenWB = False
For Each WB In Workbooks
If UCase(Trim(WB.Name)) = UCase(DingEName) Then
bOpenWB = True
Exit For
End If
Next WB
On Error GoTo Error1
'On Error Resume Next
'MsgBox DingEPath & DingEName
'Set wb1 = Workbooks(DingEPath & DingEName)
' MsgBox wb1.Name
'If wb1 Is Nothing Then
If bOpenWB = False Then
' If Not (Workbooks(Dir(DingEPath & DingEName)).IsAddin) = True Then
' myApp.Visible = False
'myApp.Visible = True
' myApp.Workbooks.Open DingEPath & DingEName, 0, bOpenReadOnly
Workbooks.Open DingEPath & DingEName, 0, bOpenReadOnly
Workbooks(DingEName).Sheets("程序").Cells(1, 1) = User_Grade
Workbooks(DingEName).Sheets("程序").Cells(2, 1) = G_TJ_Name
Workbooks(DingEName).Sheets("程序").Cells(3, 1) = False
Workbooks(DingEName).Sheets("程序").Cells(4, 1) = DingEName
'Call DEB_open(DingEName)
Else
Workbooks(DingEName).Activate
End If
G_ZCK_Name = ActiveWorkbook.Name
Workbooks(Dir(DingEPath & DingEName)).IsAddin = True
Workbooks(G_TJ_Name).Activate
|
|