question

EduardsGzibovskis-2327 avatar image
0 Votes"
EduardsGzibovskis-2327 asked EduardsGzibovskis-2327 commented

The type 'VBE' is defined in an assembly that is not referenced. You must add a reference to assmblt 'Microdoft.Vbe.Interop'...

128677-untitled2.jpg


I keep getting this error above.

I then Tried adding this top reference (See image below).

128647-untitled.jpg

But this not solve the error.

How do I fix the issue?

Thanks,
Ed


windows-wpf
untitled2.jpg (30.9 KiB)
untitled.jpg (44.7 KiB)
· 4
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

Hi,@ EduardsGzibovskis-2327. Could you show me your complete code to analyze and reproduce the problem?

0 Votes 0 ·

Hi,


This works on .NET Framework but not on .NET 5.0

Also, I realised the following:

.NET Framework:

VBE shows up

128988-image.png


.NET 5.0:

VBE does not show up

129043-image.png

See below example:


 using Excel = Microsoft.Office.Interop.Excel;
    
 // Load Excel sheet
 var excelApp = new Excel.Application();
 Excel.Workbooks books = excelApp.Workbooks;
 Excel._Workbook sheet = books.Open("path to Excel");
    
 // Load macro to excel
 excelApp.VBE .ActiveVBProject.VBComponents.Item("Sheet1").CodeModule.AddFromFile(@"G:\Templates\VBA.txt");
    
 // Show the file
 excelApp.Visible = true;
    
 // Run the internal Macro
 excelApp.Application.Run("Sheet1.merg");


0 Votes 0 ·
image.png (6.9 KiB)
image.png (6.6 KiB)
HuiLiu-MSFT avatar image HuiLiu-MSFT EduardsGzibovskis-2327 ·

Hi,@ EduardsGzibovskis-2327. May I know if you have got any chance to check my answer? I am glad to help if you have any others questions. 

0 Votes 0 ·
Show more comments

1 Answer

HuiLiu-MSFT avatar image
1 Vote"
HuiLiu-MSFT answered

The error shows that Microdoft.Vbe.Interop is missing. So I tried to add ExcelDna.Interop, which contains Microdoft.Vbe.Interop. You could try to see if it matches your program.
129724-1.png
And then the error disappeared.
129656-2.png


If the response is helpful, please click "Accept Answer" and upvote it.
 Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread. 


1.png (43.9 KiB)
2.png (34.8 KiB)
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.