Question Opening excel file and execute Open_Workbook()

snuffthepunk

New member
Joined
Jan 26, 2015
Messages
1
Programming Experience
Beginner
Hey people,

First question on the forum after getting a lot of usefull info. I have been using VBA a lot recently and wanted to switch to VB.net.

I am trying to do the following. I have an Excel file that contains this:

VB.NET:
Private Sub Workbook_Open()
Application.Visible = False
menu.Show
End Sub

I would like to open this workbook using vb.net.

I wrote the following in vb.net

VB.NET:
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles add.Click


        Dim xlApp As New Excel.Application
        Dim xlWorkBook As Excel.Workbook


        xlWorkBook = xlApp.Workbooks.Open(Application.StartupPath & "\" & "myfile.xlsm")


        xlApp.Visible = True
         

    End Sub

Now... This opens my excel file fine after adding a reference, but it does not execute the macro inside workbook_open. Instead, it shows excel with the worksheet, which is something my users should not be able to see.

Before this I used a file open dialog in vb.net, which did trigger the
VB.NET:
Application.Visible = False
menu.Show
just fine.

Forgive my noobishness... I have a lot to learn. How do I open the excel file and execute the Workbook_open code in it? Anyone who can help me out a bit?

Thanks!
 
Top Bottom