01-16-2014 06:55 AM
Hey there,
I got a script that creates *.TDM files. The annoying part is that i have to right click everytime on the created file to convert it with the TDM EXCEL ADD INN and save it with the same name like the created *.TDM file.
So, I wanted to implement it in my script but it doesn´t work.
There a piece of code i found here in the Community but in the line which says "oComAddIn.connect = True" occurs an error.
Dim oExcel
Dim oComAddIn
Set oExcel = CreateObject("Excel.Application")
For Each oComAddIn In oExcel.COMAddIns
If oComAddIn.ProgId = "ExcelTDM.TDMAddin"Then
oComAddIn.connect =True
IfNot oComAddIn.Object IsNothingThen' use the object interface here
Else
MsgBox"No object interface available! :-((("
EndIf
EndIf
Next
I´m very thankful for every help.
Solved! Go to Solution.
01-16-2014 07:31 AM
Hi,
you do not have to loop over all COMAddIns, simply use the Item() Method for COMAddIns to get the AddIn you want.
The oComAddin.connect = True is only necessarry if called from within Excel.
The following code should work as expected
Dim oExcel Dim oComAddIn Dim myBasePath : myBasePath = "C:\data\" Dim myFilename : myFilename = "MyFilename" Set oExcel = CreateObject("Excel.Application") Set oComAddIn = oExcel.Application.COMAddIns.Item("ExcelTDM.TDMAddin") oComAddIn.Object.ImportFile myBasePath & myFilename & ".tdm" oExcel.Application.Workbooks(1).SaveAs myBasePath & myFilename & ".xlsx"
Hope this helps
01-16-2014 08:44 AM
Hey,
thank you very very much. It works but it occured another problem.
I try to open the file and it opens itself twice. One file has no name, the other file has the desired name but it is in the read only mode.
When i try to delete all it´s not possible because Windows thinks it has acces to this new file.
Can you help me in this case again?
01-16-2014 09:00 AM
After running the script, please take a look into the task manager of Windows. Is Excel still running?
If yes, the following lines should close Excel at the end of the script:
oExcel.Application.Quit Set oComAddIn = Nothing Set oExcel = Nothing
01-16-2014 09:26 AM
Thank you sooo much!!!!