Josh Hazel
01-26-2010, 12:37 PM
What would/might cause Workbook_Open() event to continuously loop? My workbook_open keeps running multiple times for some reason, neverending
Excel VBA Workbook_Open Endless LoopJosh Hazel 01-26-2010, 12:37 PM What would/might cause Workbook_Open() event to continuously loop? My workbook_open keeps running multiple times for some reason, neverending Colin Legg 01-26-2010, 03:05 PM What code is in the Workbook_Open() event handler? Josh Hazel 01-27-2010, 05:08 PM Workbook_Open code Dim blnChanged As Boolean Dim i As Integer blnChanged = False With Sheets("FormPositions") .Range("B2:F30").Clear End With Dim fs As Object Dim FileName As String 'Get desktop address Set fs = CreateObject("Scripting.FileSystemObject") FileName = (DTAddress & "PW_JobAid.xls") 'Check resolution / See if new user or PW_JobAid file doesnt exist If fs.FileExists(FileName) And Replace(Right(GetScreenResolution, 4), "x", "") < 1024 Then frmUsernamesPasswords.chkClose = True frmUsernamesPasswords.Show ElseIf Not fs.FileExists(FileName) Then MsgBox _ "As a first time user, please complete the requested information on the next page." frmUP.Show End If frmUP.chkOpened = False 'You might wonder why the loop...? For some reason the form wasnt displaying, the loop fixed the problem Do Until frmMenu.Visible = True frmMenu.Show Loop ActiveWorkbook.EnableAutoRecover = False 'Create shortcut for JobAid on desktop For i = 1 To 3 Dim oldPath As String, newPath As String oldPath = "O:\jhazel\JobAid.lnk" 'Copy shortcut to desktop If i = 1 Then newPath = CreateObject("WScript.Shell").SpecialFolders("Desktop") & Application.PathSeparator 'Copy shortcut to quicklaunch If i = 2 Then newPath = "C:\Documents and Settings\" & Environ("Username") & "\Application Data\Microsoft\Internet Explorer\Quick Launch" Set fs = CreateObject("Scripting.FileSystemObject") fs.CopyFile oldPath, newPath Set fs = Nothing i = i + 1 Next i Application.Workbooks.Parent.Visible = False The UP and Menu userform's initialize will likely be triggered in all cases as well... as you see above... Btw, the copy shortcut to desktop code above works, but the copy to quicklaunch doesnt ... if u have any comments about how to make that work too =p HaHoBe 01-27-2010, 10:31 PM Hi, Josh, my guess: the code in the Workbook_Open is stopped when the userform is displayed (status would be leave the loop) and will only continue if it´s unloaded (pitfall because it´s not displayed any more). Have you tried a boolean variable to determine the status and question the status of that variable instead of using a loop? Ciao, Holger Josh Hazel 01-28-2010, 03:23 PM I tried inserting a boolean (global) and in the workbook_open, set to check if = true to exit, the next like i set the boolean = true... it was still looping, but it exited each time, ran again, exited due to boolean, again again again ... Somehow this problem stopped on its own, but ive been having unusual excel crashes (see other thread) where excel would crash and go into autorecovery (if i dont break while it was starting up with the prol above, it would crash after a few seconds) Im still trying to figure out cause/solution of that random crashes .... (again see other post) perhaps these two prol are linked. HaHoBe 01-28-2010, 09:59 PM Hi, Josh, Dim blnOpenFrmMenu As Boolean '... blnOpenFrmMenu = False 'You might wonder why the loop...? For some reason the form wasnt displaying, the loop fixed the problem Do blnOpenFrmMenu = True frmMenu.Show Loop Until blnOpenFrmMenu '... Ciao, Holger Josh Hazel 01-29-2010, 07:45 PM Ahh stupid me ... hmm well i cant really try that now, for some reason it fixed itself... Not sure whats causing all this strange stuff... co-worker opened the workbook today and it caused her excel to crash... she rebooted her pc and and opened the workbook again and there was no crash... Seems like some very strange stuff is goin on |
EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum