Announcements
Attention for Customers without Multi-Factor Authentication or Single Sign-On - OTP Verification rolls out April 2025. Read all about it here.
Ralf_Krieg
in reply to: johan.degreef

Hello

 

The GetObject method gives correct an error if Excel is simply not running and the PathName argument is omitted. Simply add an empty string and GetObject creates a new Excel.Application instance.

 

ExcelApp = GetObject("", "Excel.Application")

 

This way is not possible if you want to use a running instance. You can use a try-catch statement

 

Try
	ExcelApp = GetObject(, "Excel.Application")
	For Each wb In ExcelApp.workbooks
		If UCase(wb.fullname) = UCase(Filename) Then
			Exit For
		End If
	Next
Catch
	GoExcel.Open("C:\Autodesk en Templates\PTN_Part_Library\New_PTN_Part_Library.xlsx")
	'GoExcel.Open("C:\Users\ef\Desktop\New_PTN_Part_Library.xlsx")
End Try

 

 

or an On Error Resume next.

 

On Error Resume Next

ExcelApp = GetObject(, "Excel.Application")
opened = False

For Each wb In ExcelApp.workbooks
	If UCase(wb.fullname) = UCase(Filename) Then
		opened = True
		Exit For
	End If
Next

If Not opened Then
	GoExcel.Open("C:\Autodesk en Templates\PTN_Part_Library\New_PTN_Part_Library.xlsx")
	'GoExcel.Open("C:\Users\ef\Desktop\New_PTN_Part_Library.xlsx")
End If

On Error GoTo 0

 

 

 


R. Krieg
RKW Solutions
www.rkw-solutions.com