38 Instances/Processes of EXCEL Running!??!?!?!?

mrlemmer11

New Member
Joined
Jun 8, 2015
Messages
32
Hi all,

So, im working in WORD VBA and I have the following code to call my excel document for information. As I am doing multiple edits/testing to my WORD VBA UserForms, I am constantly starting and stopping my UF often time with code errors. After a couple hours I wanted to edit the source Excel file, but it said it was locked by another user (me) and I had to wait. I looked in task manager and saw EXCEL listed 38 times..... so I am apparently not closing the call to it correctly. Can anyone help? Thanks!

Code:
Private Sub Userform_Initialize()
Dim sourcedoc
Dim oExcel As Excel.ApplicationDim oWB As Workbook
Set oExcel = New Excel.Application
D


Application.ScreenUpdating = False
Set sourcedoc = oExcel.Workbooks.Open(FileName:="C:\users\michael\Desktop\SongIndex\BASlist.xlsx")


arBand = Range("L2:L9")
arAlbum = Range("I2:J245")
arSong = Range("E2:G298")


sourcedoc.Close SaveChanges:=wdDoNotSaveChanges
End Sub
 

Excel Facts

Repeat Last Command
Pressing F4 adds dollar signs when editing a formula. When not editing, F4 repeats last command.

GCExcel

New Member
Joined
Apr 11, 2013
Messages
48
Hello,
Not sure if it will help, but maybe try by adding this line of code at the end.

Code:
Set oExcel = Nothing
 
Upvote 0

Leith Ross

Well-known Member
Joined
Mar 17, 2008
Messages
1,874
Office Version
  1. 2010
  2. 2007
Platform
  1. Windows
Hello mrlemmer11,

A better approach is to create a single instance of the application and the quit the application when you macro is finished. You can achieve this by assigning the application object to a global variable,

Code:
Global oExcel As Object

Private Sub Userform_Initialize()

    Dim sourcedoc   As Object
    Dim oWB         As Workbook
    
        If oExcel Is Nothing Then
            Set oExcel = CreateObject("Excel.Application")
        End If
        
        Application.ScreenUpdating = False
        Set sourcedoc = oExcel.Workbooks.Open(Filename:="C:\users\michael\Desktop\SongIndex\BASlist.xlsx")

        arBand = Range("L2:L9")
        arAlbum = Range("I2:J245")
        arSong = Range("E2:G298")

        sourcedoc.Close SaveChanges:=wdDoNotSaveChanges
        
        oExcel.Quit
        
End Sub
 
Upvote 0

Forum statistics

Threads
1,195,858
Messages
6,011,978
Members
441,661
Latest member
Pammie007

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Top