views:

103

answers:

1

I have a vb.net program that opens up an excel workbook and runs a macro ("Report") in that workbook when a button is clicked.

//Workbook with macro and form
xlWorkbook = xlApp.Workbooks.Open("W:Data\Excel Program.xls")      
//Macro:
xlApp.Run("Report")      
//Macro opens form from workbook.  I browse for my two .csv files
//and then click a button to run code that creates my reports.
//form closes, show the excel report after its created
xlApp.Visible = True

After I browse my first file and select it so that its location is displayed in my text box, the excel form then hides behind any open windows. I want this form to stay on top.

It is after this code executes that the form will hide behind all other open windows:

Private Sub btnBrowseFile1_Click()
    Dim fileName1 As String
    fileName1 = Application.GetOpenFilename("CSV file (*.csv), *.csv")
    If fileName1 <> "False" Then
        Me.txtFileName1.text = fileName1
    End If
End Sub

EDIT: I still have no luck with this problem. When the excel macro is opened from a vb program I have this hiding issue...but only after browsing for a file. Why does the focus leave the form and go to Windows after browsing a file? Any one have any suggestions?

A: 

How about using AppActivate to bring the form (and the application) to the front?

http://msdn.microsoft.com/en-us/library/dyz95fhy.aspx

Raj More
I tried using AppActivate in the vb.net program after opening workbook with no luck. I added more code from my excel form to show when the form hides. What causes the form to hide when I run the macro from a vb.net program? It does not hide when I run the macro from within excel manually.
ScottK