omnibuster
05-08-2011, 02:41 AM
Hi.
If Wbk2(Two.xls) open with macro SubOne (in Wbk CallTwo....xls) how disable/enable run WbkOpenEvents?
:banghead: What I do wrong?
Code in Wbk CallTwo..
Public Allow As Boolean
Sub One()
Allow = True
Call Failikontr
End Sub
Sub Failikontr()
Dim FilePath, FName As String, WB As Workbook
If IsWkbOpened("Two.xls") Then
Windows("Two.xls").Activate
Else
FilePath = ActiveWorkbook.Path
If Right$(FilePath, 1) <> "\" Then FilePath = FilePath & "\"
FName = "Two.xls"
Set WB = Workbooks.Open(FilePath & FName, UpdateLinks:=0)
End If
End Sub
Function IsWkbOpened(sWkbName As String) As Boolean
Dim i As Long
For i = Workbooks.Count To 1 Step -1
If Workbooks(i).Name = sWkbName Then
Exit For
End If
Next
If i = 0 Then
IsWkbOpened = False
Else
IsWkbOpened = True
End If
End Function
Code in Wbk Two.
Public Allow As Boolean
Public Sub Workbook_Open()
If Allow = False Then
'Disable Wbk open event
Exit Sub
Else
Call PostMsg(Allow)
'Run Wbk_Open_Event code only if Allow = true
Call PostMsg(Allow)
End If
End Sub
Public Function PostMsg(Allow As Boolean)
MsgBox Allow & vbCrLf & vbCrLf & "Should be True????"
End Function
If Wbk2(Two.xls) open with macro SubOne (in Wbk CallTwo....xls) how disable/enable run WbkOpenEvents?
:banghead: What I do wrong?
Code in Wbk CallTwo..
Public Allow As Boolean
Sub One()
Allow = True
Call Failikontr
End Sub
Sub Failikontr()
Dim FilePath, FName As String, WB As Workbook
If IsWkbOpened("Two.xls") Then
Windows("Two.xls").Activate
Else
FilePath = ActiveWorkbook.Path
If Right$(FilePath, 1) <> "\" Then FilePath = FilePath & "\"
FName = "Two.xls"
Set WB = Workbooks.Open(FilePath & FName, UpdateLinks:=0)
End If
End Sub
Function IsWkbOpened(sWkbName As String) As Boolean
Dim i As Long
For i = Workbooks.Count To 1 Step -1
If Workbooks(i).Name = sWkbName Then
Exit For
End If
Next
If i = 0 Then
IsWkbOpened = False
Else
IsWkbOpened = True
End If
End Function
Code in Wbk Two.
Public Allow As Boolean
Public Sub Workbook_Open()
If Allow = False Then
'Disable Wbk open event
Exit Sub
Else
Call PostMsg(Allow)
'Run Wbk_Open_Event code only if Allow = true
Call PostMsg(Allow)
End If
End Sub
Public Function PostMsg(Allow As Boolean)
MsgBox Allow & vbCrLf & vbCrLf & "Should be True????"
End Function