"Unhandled exception has occurred...Object reference not set to an instance of an object" after running a macro.

mrnacar

Board Regular
Joined
Jan 27, 2010
Messages
193
Office Version
  1. 365
Platform
  1. Windows
Why am I getting the following error message after running my macro. Is there anything wrong with my macro? It seems my macro runs completely, but once it's done, I get the following error which is annoying.

Error.jpg


VBA Code:
Sub Auto_Open()
ActiveWorkbook.UpdateLink Name:=ActiveWorkbook.LinkSources
Dim year4 As String
Dim year2 As String
year4 = Range("B2").Value
year2 = Range("B3").Value
Application.ScreenUpdating = False
Application.DisplayAlerts = False
    Workbooks.Open Filename:="\\pfcoffice3\" & year4 & " Reports\PFC\COLREC" & year2 & "\Recovery\SCC_Vendor_Template.xlsx"
    Application.Run "ssgenallquerydetail"
    ActiveWorkbook.Save
    ActiveWorkbook.Close
Application.ScreenUpdating = True
Application.DisplayAlerts = False
ThisWorkbook.Saved = True
Application.Quit
End Sub
 

Excel Facts

Links? Where??
If Excel says you have links but you can't find them, go to Formulas, Name Manager. Look for old links to dead workbooks & delete.
You shouldn't be getting a .Net error from a VBA macro. What does ssgenallquerydetail do?
 
Upvote 0
You shouldn't be getting a .Net error from a VBA macro. What does ssgenallquerydetail do?
It executes a query within an application called "Spreadsheet Server Suite" made by insightsoftware. It seems it's only isolated to one machine because I ran the same exact macro on another machine with no .Net error after it completed. Any experts in here to resolve this .Net error?
 
Upvote 0
I created a simple macro and added Application.Quit at the end of my simple macro and still get the .Net error. I'm assuming it has something to do with running Application.Quit in vba? However, when I manually closed excel, I don't get the .Net error.
 
Upvote 0
I added "MsgBox "Macro Completed!" right before Application.Quit to create some sort of delay and I don't get the .Net error. Now I'm trying to figure what is the difference between this machine and the other machine that doesn't get the .Net error that does not a require a delay before Application.Quit and so far, the only difference I see is the Spreadsheet Server Suite version. The one with no issues has version 24.2 and the one with the issue has version 23.1 I may just need to upgrade or add a delay right before Application.Quit I may have answered my own question but if anyone else has a better solution, please feel free to post.
 
Last edited:
Upvote 0
FYI: adding
Code:
Application.Wait Now + #0:00:01#
before Application.Quit solved my problem.
 
Upvote 0

Forum statistics

Threads
1,225,490
Messages
6,185,294
Members
453,285
Latest member
Wullay

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
Back
Top