Vba excel ошибка 361

This is my code for listing two text boxes and to select data from one to another. Previously it was working fine. Now it keep on showing "Could not load or unload this object"

I tried removing option explicit , I deleted a module which was opening this form. Nothing is working. I a added a button click command and then it showed this error. On button click, I just tried to hide this form and show another form. But after that on wards this error is shown. I removed that lines of code and tried. Still it is not working

My code :

Private Sub BTN_moveAllLeft_Click()

    Dim iCtr As Long

    For iCtr = 0 To Me.ListBox2.ListCount - 1
        Me.ListBox1.AddItem Me.ListBox2.List(iCtr)
    Next iCtr

    Me.ListBox2.Clear
End Sub
Private Sub BTN_moveAllRight_Click()

    Dim iCtr As Long

    For iCtr = 0 To Me.ListBox1.ListCount - 1
        Me.ListBox2.AddItem Me.ListBox1.List(iCtr)
    Next iCtr

    Me.ListBox1.Clear
End Sub
Private Sub BTN_MoveSelectedLeft_Click()

    Dim iCtr As Long

    For iCtr = 0 To Me.ListBox2.ListCount - 1
        If Me.ListBox2.Selected(iCtr) = True Then
            Me.ListBox1.AddItem Me.ListBox2.List(iCtr)
        End If
    Next iCtr

    For iCtr = Me.ListBox2.ListCount - 1 To 0 Step -1
        If Me.ListBox2.Selected(iCtr) = True Then
            Me.ListBox2.RemoveItem iCtr
        End If
    Next iCtr

End Sub
Private Sub BTN_MoveSelectedRight_Click()

    Dim iCtr As Long

    For iCtr = 0 To Me.ListBox1.ListCount - 1
        If Me.ListBox1.Selected(iCtr) = True Then
            Me.ListBox2.AddItem Me.ListBox1.List(iCtr)
        End If
    Next iCtr

    For iCtr = Me.ListBox1.ListCount - 1 To 0 Step -1
        If Me.ListBox1.Selected(iCtr) = True Then
            Me.ListBox1.RemoveItem iCtr
        End If
    Next iCtr

End Sub

'Private Sub cancel_Click()
'Unload.Me
'End Sub

'Private Sub cmdOK_Click()
'frmListBoxTest.Hide
' UserForm2.Show
'End Sub


Private Sub UserForm_Initialize()

    Dim iCtr As Long

    With Me.ListBox1

            .AddItem "1"
            .AddItem "B"
            .AddItem "D"
            .AddItem "G"
            .AddItem "A"
            .AddItem "BS"
            .AddItem "MR"
            .AddItem "Ig"
            .AddItem "Eng"
            .AddItem "BE"
            .AddItem "CS"
            .AddItem "PS"
            .AddItem "C"
            .AddItem "TN"
            .AddItem "HC"
            .AddItem "Cy"
            .AddItem "P"
            .AddItem "Dr"
            .AddItem "ER"


    End With



    Me.ListBox1.MultiSelect = fmMultiSelectMulti
    Me.ListBox2.MultiSelect = fmMultiSelectMulti

End Sub

Previously there was a module named module 1 which had the code to show this userform.

And Option Explicit was also there in this form code. I removed that.

Images of errors :

enter image description here
enter image description here

asked Mar 19, 2018 at 6:23

qwww's user avatar

5

It used to work, now it doesn’t. Most likely reason, if you haven’t changed anything, is that the compiled code is corrupt.

Step 1: export all modules and forms from the vb editor. 
Step 2: save the file as an xlsx (thus removing all vb code)
step 3: Open the xlsx and import all the modules and forms
Step 4: recompile the code (debug,compile)
step 5: save as xlsm 

answered Mar 19, 2018 at 13:45

Harassed Dad's user avatar

Harassed DadHarassed Dad

4,6691 gold badge10 silver badges12 bronze badges

Search code, repositories, users, issues, pull requests…

Provide feedback

Saved searches

Use saved searches to filter your results more quickly

Sign up

Russ At Index

Well-known Member

Joined
Sep 23, 2002
Messages
704
Office Version
  1. 365
  2. 2016
Platform
  1. Windows
  2. MacOS


charllie

Well-known Member

Joined
Apr 6, 2005
Messages
986


  • #3

Hi Russ,

Thanks for that, a nice site to keep in my favourites.

Unfortunately i couldn’t solve the error. Did a serach on here prior to my post and it seems most people with that problem ended up deleting the form. So i had to with mine.

Anyway thanks for your help, i appreciate it.

  • Home
  • Forum
  • Microsoft Office Application Help — Excel Help forum
  • Excel Programming / VBA / Macros
  • [SOLVED] Run-Time Error ‘361

  1. 01-29-2014, 03:05 PM


    #1

    rlkerr is offline


    Forum Contributor


    Run-Time Error ‘361

    My macro seems to run fine, but then it pops up with this Run-Time error ‘361 Application-defined or object-defined error.

    How do I know where my error is in my code?


  2. 01-29-2014, 03:08 PM


    #2

    Re: Run-Time Error ‘361

    If you go to the module that you have the code,after you got the error, you’ll sse a line of the code highlighteed in yellow color.


Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Replies: 1

    Last Post: 10-11-2013, 07:04 AM

  2. Replies: 2

    Last Post: 09-11-2013, 07:26 AM

  3. Replies: 7

    Last Post: 05-15-2013, 09:02 AM

  4. Replies: 0

    Last Post: 11-02-2012, 09:31 AM

  5. Replies: 2

    Last Post: 07-16-2012, 09:55 AM

Bookmarks

Bookmarks

INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Contact US

Thanks. We have received your request and will respond promptly.

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!

  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It’s Free!

*Tek-Tips’s functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

«Unload Me» question «Runtime error 361 Can’t load/unload this ob

«Unload Me» question «Runtime error 361 Can’t load/unload this ob

(OP)

19 Aug 04 14:54

Hi again,
I have found and modified the following code to suit my needs but the «Unload Me» keeps frustrating me. Don’t really know whether or not I need it either.
It appears to work OK without it but as it was there intially am wondering why???
Appreciate any help with this I am more curious than….

CODE

Dim strAddItem As String
    strAddItem = ProdProcEntry.Text
    If strAddItem = «» Then
        MsgBox «Enter something intelligent, Please!!»
      FocusTextBox
        Exit Sub
    Else
        Dim aDoc As Document
        Set aDoc = ActiveDocument
        aDoc.FormFields(«DropdownProdProc»).Result = strAddItem
        Set aDoc = Nothing
    End If
     Unload Me
End Sub

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Join Tek-Tips® Today!

Join your peers on the Internet’s largest technical computer professional community.
It’s easy to join and it’s free.

Here’s Why Members Love Tek-Tips Forums:

  • Tek-Tips ForumsTalk To Other Members
  • Notification Of Responses To Questions
  • Favorite Forums One Click Access
  • Keyword Search Of All Posts, And More…

Register now while it’s still free!

Already a member? Close this window and log in.

Join Us             Close

  • Home
  • VBForums
  • Visual Basic
  • Visual Basic 6 and Earlier
  • VB6 Run Time Error 361 Can’t Load or unload this object

  1. May 13th, 2020, 01:40 PM

    #1

    Vido is offline

    Thread Starter


    New Member


    VB6 Run Time Error 361 Can’t Load or unload this object

    Hey guys, Im in process of making memory game, I followed video instructions but I can get it to work Im getting an error

    Code:

    Run Time Error 361 Can't Load or unload this object

    and it points to

    Code:

    Load btnChoice(intNextNumber)

    And here is my code

    Code:

    Option Explicit
    
    'Variable to Check Playing Turn
        Private boolFirstChoice As Boolean
    
    'Variable For Previous Index Chosen
        Private intFirstChoice As Integer
    
    'Variable For Comparing Choices
        Private astrChoice(1 To 2) As String
    
    'Variable For Keeping Pictures Visable
        Private aboolVisablePositions(1 To 8) As Boolean
    
    'Note: Take Note Of The Properties On The Button And Image Boxes
    
    Private Sub Form_Load()
    
    'Declare
        Dim intNextNumber As Integer 'Loop
    
    
    'Load 8 Buttins And 8 Image Boxes
        For intNextNumber = 1 To 8
            Load btnChoice(intNextNumber)
            Load imgPicture(intNextNumber)
        Next
    
    'Move The Buttons And Image Boxes
        Call MoveControls(btnChoice)
        Call MoveControls(imgPicture)
    
    'Make All Buttons Visable
        For intNextNumber = 1 To 8
        btnChoice(intNextNumber).Visable = True
        Next
    
    'Set The Randomize Generator
        Randomize
    
    'Declare Temporary
        Dim aintRandomNumber(1 To 8) As Integer
    
    'Get Random Numbers
        Call GetRandomNumbers(aintRandomNumber)
    
    'Load The Pictures
    
        For intNextNumber = 1 To 8
            Select Case aintRandomNumber(intNextNumber)
                Case 1, 2 'Santa
                    imgPicture(intNextNumber).Picture = _
                        LoadPicture(App.Path & "Santa.jpg")
                    'Set Tag
                     imgPicture(intNextNumber).Tag = "Santa"
                Case 3, 4 'Gifts
                    imgPicture(intNextNumber).Picture = _
                        LoadPicture(App.Path & "Gifts.jpg")
                    'Set Tag
                     imgPicture(intNextNumber).Tag = "Gifts"
                Case 5, 6 'Rudolph
                    imgPicture(intNextNumber).Picture = _
                        LoadPicture(App.Path & "Rudolph.jpg")
                    'Set Tag
                     imgPicture(intNextNumber).Tag = "Rudoplph"
                Case 7, 8 'ChristmasTree
                    imgPicture(intNextNumber).Picture = _
                        LoadPicture(App.Path & "ChristmasTree.jpg")
                    'Set Tag
                     imgPicture(intNextNumber).Tag = "ChristmasTree"
             End Select
        Next
    
    End Sub
                     
    
    Private Sub MoveControls(objControl As Object)
    
    'Move Controls
        objControl(1).Move 8, 8
        objControl(2).Move 168, 8
        objControl(3).Move 328, 8
        objControl(4).Move 488, 8
        objControl(5).Move 8, 160
        objControl(6).Move 168, 160
        objControl(7).Move 328, 160
        objControl(8).Move 488, 160
    
    End Sub
    
    Private Sub GetRandomNumbers(aintRandomNumber() As Integer)
    
    ' Pick A Random Nuber 1 Trough 8
        aintRandomNumber(1) = CInt((Rnd * 7) + 1)
    
    'Pick A Different Number
        Do Until aintRandomNumber(2) <> aintRandomNumber(1) _
        And aintRandomNumber(2) <> 0
            aintRandomNumber(2) = CInt((Rnd * 7) + 1)
        Loop
    
    'Pick A Different Number
        Do Until aintRandomNumber(3) <> aintRandomNumber(2) _
        And aintRandomNumber(3) <> aintRandomNumber(1) _
        And aintRandomNumber(3) <> 0
        aintRandomNumber(3) = CInt((Rnd * 7) + 1)
    
    'Pick A Different Number
        Do Until aintRandomNumber(4) <> aintRandomNumber(3) _
        And aintRandomNumber(4) <> aintRandomNumber(2) _
        And aintRandomNumber(4) <> aintRandomNumber(1) _
        And aintRandomNumber(4) <> 0
            aintRandomNumber(4) = CInt((Rnd * 7) + 1)
        Loop
    
    'Pick A Different Number
        Do Until aintRandomNumber(5) <> aintRandomNumber(4) _
        And aintRandomNumber(5) <> aintRandomNumber(3) _
        And aintRandomNumber(5) <> aintRandomNumber(2) _
        And aintRandomNumber(5) <> aintRandomNumber(1) _
        And aintRandomNumber(5) <> 0
            aintRandomNumber(5) = CInt((Rnd * 7) + 1)
        Loop
    
    'Pick A Different Number
        Do Until aintRandomNumber(6) <> aintRandomNumber(5) _
        And aintRandomNumber(6) <> aintRandomNumber(4) _
        And aintRandomNumber(6) <> aintRandomNumber(3) _
        And aintRandomNumber(6) <> aintRandomNumber(2) _
        And aintRandomNumber(6) <> aintRandomNumber(1) _
        And aintRandomNumber(6) <> 0
            aintRandomNumber(6) = CInt((Rnd * 7) + 1)
        Loop
    
    'Pick A Different Number
        Do Until aintRandomNumber(7) <> aintRandomNumber(6) _
        And aintRandomNumber(7) <> aintRandomNumber(5) _
        And aintRandomNumber(7) <> aintRandomNumber(4) _
        And aintRandomNumber(7) <> aintRandomNumber(3) _
        And aintRandomNumber(7) <> aintRandomNumber(2) _
        And aintRandomNumber(7) <> aintRandomNumber(1) _
        And aintRandomNumber(7) <> 0
            aintRandomNumber(7) = CInt((Rnd * 7) + 1)
        Loop
    
    'Pick A Different Number
        Do Until aintRandomNumber(8) <> aintRandomNumber(7) _
        And aintRandomNumber(8) <> aintRandomNumber(6) _
        And aintRandomNumber(8) <> aintRandomNumber(5) _
        And aintRandomNumber(8) <> aintRandomNumber(4) _
        And aintRandomNumber(8) <> aintRandomNumber(3) _
        And aintRandomNumber(8) <> aintRandomNumber(2) _
        And aintRandomNumber(8) <> aintRandomNumber(1) _
        And aintRandomNumber(8) <> 0
            aintRandomNumber(8) = CInt((Rnd * 7) + 1)
        Loop
    
    End Sub
    
    Private Sub btnChoice_Click(Index As Integer)
    
    'Check Turn
        If boolFirstChoice = False Then
            astrChoices(1) = imgPicture(Index).Tag
            intFirstChoice = Index
            boolFirstChoice = True
        Else
            astrChoices(2) = imgPicture(Index).Tag
            boolFirstChoice = False
        End If
    
    'Visable Image Behind Button
        btnChoice(Index).Vasable = False
        imgPixture(Index).Visable = True
    
    'Replay  For Second Choice
    
        If boolFirstChoice = False Then
            'MsgBox The Player
            If astrChoice(1) = astrChoice(2) Then
            aboolVisablePositions(intFirstChoice) = True
            aboolVisablePositions(Index) = True
                MsgBox "Matched"
            Else
                MsgBox "Not matched"
            End If
            'Undo Choice
            Call UndoChoice
        End If
    
    'If All Positions Are Visable Exit Program
        If AllPostionsVisable = True Then
            MsgBox "Game done"
            End
        End If
    End Sub
    
    Private Sub UndoChoice()
    
    'Declare
        Dim intNextNumber As Integer
    
    'Show All Buttons
        For intNextNumber = 1 To 8
            If btnChoice(intNextNumber).Visable = False _
            And aboolVisablePostions(intNextNumber) = False Then
                btnChoice(intNextNumber).Visable = True
                imgPixture(intNextNumber).Visable = False
            End If
        Next
    
    End Sub
    
    Private Function AllPositionsVisable() As Boolean
    
    'Declare
        Dim intNextNumber As Integer
    'Check All positions
        For intNextNumber = 1 To 8
            If aboolVisablePosition(intNextNumber) = False Then
                AllPositionsVisable = False
                Exit Function
            End If
        Next
    'Return
        AllPositionsVisable = True
    End Function
    
    
    'Declare
        Dim intNextNumber As Integer
    Replay
    'Check All positions
        For intNextNumber = 1 To 8
            If aboolVisablePostions(intNextNumber) = False Then
                AllPositionsVisable = False
                Exit Function
            End If
        Next
    'Return Function
        AllPositionsVisable = True
    
    End Function
    
    Private Sub Form_Unload(Cancel As Integer)
    
    'Empty Form Memory
        Set frmMemoryGame = Nothing
    End Sub

  2. May 13th, 2020, 03:07 PM

    #2

    Re: VB6 Run Time Error 361 Can’t Load or unload this object

    Didn’t download your project. Ensure btnChoice & imgPicture are indexed. In their property sheets, set Index property to zero.

    This is not the correct place for posting general VB questions. A moderator will likely move this thread.

    Welcome to the forums


  3. May 13th, 2020, 03:35 PM

    #3

    Vido is offline

    Thread Starter


    New Member


    Re: VB6 Run Time Error 361 Can’t Load or unload this object

    Quote Originally Posted by LaVolpe
    View Post

    Didn’t download your project. Ensure btnChoice & imgPicture are indexed. In their property sheets, set Index property to zero.

    This is not the correct place for posting general VB questions. A moderator will likely move this thread.

    Welcome to the forums

    Im not developer can you show me how to index them, I tried to put them = to 0 but its not that


  4. May 13th, 2020, 04:48 PM

    #4

    Re: VB6 Run Time Error 361 Can’t Load or unload this object

    In design view. Click on the control. In the property sheet where you set your button’s caption (right hand-side), you will see an «Index» property. Click in its textbox on that property sheet and type in the value 0.

    If you are still having problems, then do this…
    1. Right click on your command button, select Copy
    2. Right click on your form, select Paste
    3. When prompted to create an Indexed array, say yes (can’t recall exactly what the message says)
    4. Delete the copy and your original one will now have an Index of zero
    5. Repeat steps for the image control


  5. May 13th, 2020, 04:59 PM

    #5

    Vido is offline

    Thread Starter


    New Member


    Re: VB6 Run Time Error 361 Can’t Load or unload this object

    Metod or data member not found

    Code:

    btnChoice(intNextNumber).Visable = True

  6. May 13th, 2020, 05:05 PM

    #6

    Re: VB6 Run Time Error 361 Can’t Load or unload this object

    It’s a typo, you can just make up property names


  7. May 13th, 2020, 05:09 PM

    #7

    Vido is offline

    Thread Starter


    New Member


    Re: VB6 Run Time Error 361 Can’t Load or unload this object

    I dont understand where did I make typo


  8. May 13th, 2020, 05:12 PM

    #8

    Re: VB6 Run Time Error 361 Can’t Load or unload this object


  9. May 13th, 2020, 05:24 PM

    #9

    Vido is offline

    Thread Starter


    New Member


    Re: VB6 Run Time Error 361 Can’t Load or unload this object

    Tnx wqweto, now I have

    Code:

    Compile error: Do without Loop

    and I have indicated


  10. May 13th, 2020, 05:25 PM

    #10

    Vido is offline

    Thread Starter


    New Member


    Re: VB6 Run Time Error 361 Can’t Load or unload this object

    Thanks for helping me out guys


  11. May 13th, 2020, 05:28 PM

    #11

    Re: VB6 Run Time Error 361 Can’t Load or unload this object

    As the error indicates, you have a Do statement without a corresponding Loop statement. If you look through your code it shouldn’t be too hard to find.


  12. May 13th, 2020, 05:37 PM

    #12

    Vido is offline

    Thread Starter


    New Member


    Re: VB6 Run Time Error 361 Can’t Load or unload this object

    Aha great tnx, now I have

    Code:

    Only comment may appear after End Sub, End Function, or End Property

  13. May 13th, 2020, 05:38 PM

    #13

    Vido is offline

    Thread Starter


    New Member


    Re: VB6 Run Time Error 361 Can’t Load or unload this object

    It shows

    Code:

        If boolFirstChoice = False Then

    indicated

    and here is snippet

    Code:

        Loop
    
    End Sub
    
    
    'Check Turn
        If boolFirstChoice = False Then
            astrChoices(1) = imgPicture(Index).Tag
            intFirstChoice = Index
            boolFirstChoice = True

  14. May 13th, 2020, 05:40 PM

    #14

    Re: VB6 Run Time Error 361 Can’t Load or unload this object

    Yes, and just like the previous error message, what you are being told is a very descriptive and straightforward explanation of what the problem is.

    Good luck.


  15. May 13th, 2020, 05:42 PM

    #15

    Vido is offline

    Thread Starter


    New Member


    Re: VB6 Run Time Error 361 Can’t Load or unload this object

    Quote Originally Posted by OptionBase1
    View Post

    Yes, and just like the previous error message, what you are being told is a very descriptive and straightforward explanation of what the problem is.

    Good luck.

    but comment is behind End Sub


  16. May 13th, 2020, 05:47 PM

    #16

    Re: VB6 Run Time Error 361 Can’t Load or unload this object

    «Only comment may appear after End Sub, End Function, or End Property» means that comments are *ok* after End Sub. Only these are ok. If statements are not ok.

    cheers,
    </wqw>


  17. May 13th, 2020, 06:04 PM

    #17

    Re: VB6 Run Time Error 361 Can’t Load or unload this object

    Quote Originally Posted by Vido
    View Post

    but comment is behind End Sub

    A sub example looks like this

    Code:

    Private Sub SubName(parameters if any)
     ... code
    End Sub

    A function example looks like this

    Code:

    Private Function FunctionName(parameters if any) As Long
     ... code
    End Function

    Only executable code can go between the start/end of the method
    Between the end of one method and the start of another method, only comments may appear. If a line is not a comment, it’s executable.

    You said you are not a developer, however you are creating a game. Consider yourself a developer. You need to learn some basics. People here will help, but I doubt many are going to continue to give you copy & paste code without you understanding a bit first.


  18. May 14th, 2020, 06:25 AM

    #18

    Vido is offline

    Thread Starter


    New Member


    Re: VB6 Run Time Error 361 Can’t Load or unload this object

    Hey all
    I checked my code once again but it does not work basicly when I click button I get

    Code:

    Compile error
    Variable not defined

    and this code marked

    Code:

        If AllPostionsVisible = True Then

  19. May 14th, 2020, 06:47 AM

    #19

    Re: VB6 Run Time Error 361 Can’t Load or unload this object

    Check the spelling of AllPostionsVisible


  20. May 14th, 2020, 07:07 AM

    #20

    Vido is offline

    Thread Starter


    New Member


    Re: VB6 Run Time Error 361 Can’t Load or unload this object

    Ah typo again tnx, now I’m getting

    Code:

    Run Time Error 360
    Object Already Loaded

    And marked code is

    Code:

    Load imgPicture(intNextNumber)

  21. May 14th, 2020, 11:20 AM

    #21

    Re: VB6 Run Time Error 361 Can’t Load or unload this object

    When the error occurs, hover over the variable. VB will display the value in a tool tip. The error is self-explanatory however.

    If you are dynamically loading controls and also dynamically unloading them, then you have an error in your logic somewhere which is leaving one or more loaded. If you are are resetting the gameboard, you need to unload the controls that you have dynamically loaded before you can re-load them again — else an error like that happens.

    Tip: When VB errors occur, google it, like: «Object Already Loaded error 360 MSDN». One of the first hits, should be a link where Microsoft explains what their errors mean.


  22. May 14th, 2020, 02:38 PM

    #22

    Vido is offline

    Thread Starter


    New Member


    Re: VB6 Run Time Error 361 Can’t Load or unload this object

    Thank you all guys you have great community here


  • Home
  • VBForums
  • Visual Basic
  • Visual Basic 6 and Earlier
  • VB6 Run Time Error 361 Can’t Load or unload this object


Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
  • BB code is On
  • Smilies are On
  • [IMG] code is On
  • [VIDEO] code is On
  • HTML code is Off

Forum Rules


Click Here to Expand Forum to Full Width

Понравилась статья? Поделить с друзьями:
  • Vba excel обработчик ошибок
  • Vba excel обработка ошибок vba
  • Vba excel коды ошибок
  • Vba excel игнорировать ошибки
  • Vba end while ошибка