Eng-Tips is the largest engineering community on the Internet

Intelligent Work Forums for Engineering Professionals

  • Congratulations waross on being selected by the Eng-Tips community for having the most helpful posts in the forums last week. Way to Go!

Catia Macro: Open up Exisiting Excel from Catia 1

Status
Not open for further replies.

jcbrenn

Aerospace
May 4, 2022
1
US
Hello all,

I need to write a CATIA macro that will open up an existing excel file from catia and export some data. I have pieces of code that do something similar (see the code below) but they open up new Excel and for this macro, I would like it to open a saved template every time. Any pointers are greatly appreciated!


Code:
[/code 
'Open up Excel Part'
Dim Excel As Object
     On Error Resume Next
'if Excel is already running, then get the Excel object
           Set Excel = GetObject(, "Excel.Application")
           If Err.Number <> 0 Then
'If Excel is not already running, then create a new session of Excel
               Set Excel = CreateObject("Excel.Application")
                  Excel.Visible = True
                  Excel.Workbooks.Add
            End If
            'add a new workbook
                       
'set the workbook as the active document
        'Set WBK = Excel.ActiveWorkbook.Sheets(1)
        Set WBK = Excel.ActiveWorkbook.Sheets("Sheet2")

                                                                      ]          
                                                                      [attach_link]   [/attach_link]
 
 
Replies continue below

Recommended for you

Hello,

To open an existing file :

Dim Template as string
Template="C:\Temp\myExcelTemplate.xlsx"
Set myWorkbook = Excel.Workbooks.Open(Template)

Remove the line "Excel.Workbooks.add" from your code.

Regards
Marc
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top