Quantcast
Channel: VBForums - API
Viewing all articles
Browse latest Browse all 168

Issue while creating a dll for automating excel using VB.Net

$
0
0
Hi,

I have created a Excel macro(using VBA) which performs specific functions. Due to security reasons i have decided to create my functions in dll and distribute.

When i try to create a dll/class library in VS2013, i receive the below error in line

"An unhandled exception of type 'System.Runtime.InteropServices.COMException' occurred in PDUNZDLL.dll

Additional information: Retrieving the COM class factory for component with CLSID {00020819-0000-0000-C000-000000000046} failed due to the following error: 80040154."

Basically what i have done is created a application with a vb form along with a button. On button click, it will call a function("Click" function) inside my dll.

This is my dll name PDUNZDLL.dll

Below is my Dll code
Code:


Imports System.Runtime.InteropServices
Imports System.Text
Imports Microsoft.Win32

Public Class ATOM

    <DllImport("user32.dll", SetLastError:=True)> _
    Private Shared Function GetWindowThreadProcessId(ByVal hwnd As IntPtr, _
                                                    ByRef lpdwProcessId As Integer) As Integer
    End Function
    Public Function Click()
        Dim ExcelApp As New Microsoft.Office.Interop.Excel.Application
        Dim diffexcelapp As New Microsoft.Office.Interop.Excel.Application
        Dim wb As New Microsoft.Office.Interop.Excel.Workbook
        MsgBox(diffexcelapp.Workbooks.Count)
        MsgBox(ExcelApp.Workbooks.Count)

    End Function
End Class

It would be great if someone says what mistake i am doing here or else a piece of code or steps to reference excel to dll properly and work with excel objects.

Viewing all articles
Browse latest Browse all 168

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>