Multiple Workbook Open procedures

spidaman

Board Regular
Joined
Jul 26, 2015
Messages
96
Office Version
  1. 365
Platform
  1. Windows
Can anyone help with this please?

I have 3 different procedures in ThisWorkbook module. The problem is that when I open the workbook they are not all getting fired. I've tried various different approaches but without success so far.

The first procedure calls each of the others:

VBA Code:
Private Sub Workbook_Open()

CheckLicense
Backdoor
Shortcuts

End Sub

The project is compiled OK and each of the procedures work OK separately.
The three procedures being called are Public Subs.
The CheckLicense procedure refers to a ClassModule in case that's significant.

I think it is a simple fix, but I just can't arrange the procedures in a way that they all get fired on opening the workbook........

All comments welcome - thanks for help in advance!
 

Some videos you may like

Excel Facts

Return population for a City
If you have a list of cities in A2:A100, use Data, Geography. Then =A2.Population and copy down.

JLGWhiz

Well-known Member
Joined
Feb 7, 2012
Messages
12,705
Office Version
  1. 2013
Platform
  1. Windows
If any of the procedures are not running it would have to be caused by something other that the fact that they are called in the Workbook_Open macro. You can open the vb editor to display the Workbook_Open macro then use the F8 function key to step through the code and see where it is bypassing any of the called macros. Just follow the yellow highlighted line of code to see what is supposed to happen, and compare it to what does happen when the code executes by pressing the F8 key.
 

Joe4

MrExcel MVP, Junior Admin
Joined
Aug 1, 2002
Messages
55,393
Office Version
  1. 365
Platform
  1. Windows
It could be that something is happening in the earlier procedures that is preventing the later procedures from running (i.e. if one were to close the workbook).
Of course, we cannot tell without seeing the code behind those procedures.
Using the method JLGWhiz posted should allow you to see what exactly is happening.

If you cannot figure it out, then please post the VBA code behind the procedures so we can see what it is doing.
 

spidaman

Board Regular
Joined
Jul 26, 2015
Messages
96
Office Version
  1. 365
Platform
  1. Windows
Thanks JLGWhiz and Joe4. I'll step through again more carefully and come back with the code if I can't work it out.
 

spidaman

Board Regular
Joined
Jul 26, 2015
Messages
96
Office Version
  1. 365
Platform
  1. Windows

ADVERTISEMENT

After stepping through the ThisWorkbook code I've identified the procedure causing problems:

VBA Code:
Private Sub Workbook_Open()

Backdoor

End Sub

Public Sub Backdoor()

#If Mac Then

#Else

    If IsBackdoorRunning Then

    ThisWorkbook.Close SaveChanges:=False

    End If

#End If

End Sub

Public Function IsBackdoorRunning() As Boolean

Dim objList As Object

Set objList = GetObject("winmgmts:").ExecQuery("select * from win32_processwhere Name='VBAPass.exe' or Name='aopr.exe'")

IsBackdoorRunning = objList.Count > 0

End Function

Can anyone help with the error here. F8 step through just doesn't work when I include this procedure. Not sure why?

Thanks in advance.
 

JLGWhiz

Well-known Member
Joined
Feb 7, 2012
Messages
12,705
Office Version
  1. 2013
Platform
  1. Windows
VBA Code:
If IsBackdoorRunning Then
    ThisWorkbook.Close SaveChanges:=False
End If
With this statement being true, it is closing your workbook that you have just opened and it appears that it would always be true. But I will not make any suggestions for correcting the code because I have no idea how your other code interacts with the various functions and macros on your system. You might be better off getting someone locally to look at the code and see if they can unravel it for you.
 

spidaman

Board Regular
Joined
Jul 26, 2015
Messages
96
Office Version
  1. 365
Platform
  1. Windows
Yes I see that. OK no worries thanks for taking a look.

What is the significance of the # in the if statement here?
 

JLGWhiz

Well-known Member
Joined
Feb 7, 2012
Messages
12,705
Office Version
  1. 2013
Platform
  1. Windows
What is the significance of the # in the if statement here?
I think it is the MAC eauivalent of an apostrophe on a PC, it makes that line a comment rather than code.. It would have been clearer if whoever entered the # symbol had just deleted those lines of code, but like I said, without seeing the entire set up, I am hesitant to make any suggestions because it looks like whoever originated all the code has made some dependent macros and I would not try to do a remote analysis because the code jumps between code modules and it is easy to miss a call if doing a paper based analysis versus hands on. But maybe somebody with more patience than I have would take a shot at it.
 

Watch MrExcel Video

Forum statistics

Threads
1,118,279
Messages
5,571,288
Members
412,375
Latest member
BRJoeyMelo
Top