insert images excel

insert images excel

martinhoos
Advocate Advocate
781 Views
4 Replies
Message 1 of 5

insert images excel

martinhoos
Advocate
Advocate

Hello, i create a PDF file from a IDW and i create a excel file and insert the boom from the IDW. Is it possible, i dont know how, to insert the PDF file onto a new worksheet (sheet1)?

Thanks for the help!

Regards Martin

0 Likes
Accepted solutions (1)
782 Views
4 Replies
Replies (4)
Message 2 of 5

YuhanZhang
Autodesk
Autodesk

You can refer to Excel API to do this, below is sample code:

 

Sub ExcelInsertPDFMacroSample()
 
    Dim oWB As Workbook
    Set oWB = Application.ActiveWorkbook
    
    ' activate the first work sheet.
    oWB.Sheets(1).Activate
    
    ' insert the PDF at the A1 cell
    Range("A1").Select

    ' insert as embedded object
    ActiveSheet.OLEObjects.Add(Filename:="C:\Temp\MyPDF.pdf" _
        , Link:=False, DisplayAsIcon:=False).Select
    
    ' insert as linked object
    'ActiveSheet.OLEObjects.Add(Filename:="C:\Temp\MyPDF.pdf" _
        , Link:=True, DisplayAsIcon:=False).Select
End Sub


If this solves the problem please click ACCEPT SOLUTION so other people can find it easily.



Rocky Zhang
Inventor API PD
Manufacturing Solutions
Autodesk, Inc.

0 Likes
Message 3 of 5

martinhoos
Advocate
Advocate

Hi Rocky,

thanks a lot for your reply. Is it possible to get your code as iLogic-code? So i can place it in better.

Regards

Martin

0 Likes
Message 4 of 5

YuhanZhang
Autodesk
Autodesk
Accepted solution

I am not sure how iLogic can reference to Excel API in iLogic rule, but below is a sample for you to call Excel API via Inventor VBA Editor, you can add the reference(Tools->References...) to "Microsoft Excel xx.0 Object Library" in VBA Editor, the xx is the version of the Excel, and then in Inventor VBA run below macro:

 

Sub InsertPDFSample()
    Dim oExcel As Excel.Application

    On Error Resume Next
    Set oExcel = GetObject(, "excel.application")
    
    If Err.Number <> 0 Then
        Set oExcel = CreateObject("excel.application")
    End If
    
    oExcel.Visible = True
    
    Dim sExcelPath As String
    sExcelPath = "C:\TEMP\Test.xlsx"
    
    Dim oWorkbook As Excel.Workbook
    Set oWorkbook = oExcel.Workbooks.Open(sExcelPath)
    
    ' activate the first work sheet.
    oWorkbook.Sheets(1).Activate
    
    ' insert the PDF at the A1 cell
    oWorkbook.Sheets(1).Range("A1").Select

    ' insert as embedded object
    oWorkbook.ActiveSheet.OLEObjects.Add(FileName:="C:\Temp\MyPDF.pdf" _
        , Link:=False, DisplayAsIcon:=False).Select
    
    ' insert as linked object
    'ActiveSheet.OLEObjects.Add(Filename:="C:\Temp\MyPDF.pdf" _
        , Link:=True, DisplayAsIcon:=False).Select
End Sub


If this solves the problem please click ACCEPT SOLUTION so other people can find it easily.



Rocky Zhang
Inventor API PD
Manufacturing Solutions
Autodesk, Inc.

Message 5 of 5

martinhoos
Advocate
Advocate

Thank you very much.... !

Regards Martin

0 Likes