I have written a VB.NET function that exports data from AutoCAD and imports it into a new Excel worksheet.
The code runs as I want it to, however, when all the data has been added to Excel, I want the control to go back to AutoCAD to display a msgbox that the routine has finished.
The msgbox comes up, but it does not put focus back to AutoCAD. If the excel window is ontop of AutoCAD, the user has no idea when the routine is finished.
Any ideas how to do this would be much appreciated?
Solved! Go to Solution.
Solved! by cjacobi. See the answer in context.
Well I tried something different and got an appropriate solution. I added the following before my MsgBox.
Excel now minimizes and then Autocad is the main visible application showing my message to the user.
Not sure why I didn't find this earlier but sometime a step away brings new ideas when you return.
thanks to everyone who provided responses.
myExcel.WindowState = Microsoft.Office.Interop.Excel.XlWindowState.xlMinimized
Thanks for the response.
I added that into my code just before the MsgBox. Still no go.
In the code I'm adding rows into Excel so Excel is the active window. But when the routine is done, it still sits with Excel as the active window....I figured the MsgBox should make Autocad the active window.....even with your added suggestion, it does not bring it infront of Excel.
Won't the Excel application have a means to minimize the application window, thus restoring the AutoCAD application to the foreground?
There are some ideas posted here
if you set the excel.application visible = false does this do anything helpful?
thanks...I will check that link out.
Your sugestion of
myExcel.Application.Visible = False
Closes Excel right down....doesn't even ask to save the file.
I have done extensive work with Excel and have some good code for running it. First detect if it is running, then...
Private MyXL As Microsoft.Office.Interop.Excel.Application 'Excel.Application Private objWorkbook As Microsoft.Office.Interop.Excel._Workbook 'Excel.Workbook Private objWorksheet As Microsoft.Office.Interop.Excel._Worksheet 'Excel.Worksheet Function
... ... ... ... in closing the function: If PrintFooter = True Then objWorksheet.PageSetup.LeftFooter = System.DateTime.Today.Date objWorksheet.PageSetup.RightFooter = System.DateTime.Now.TimeOfDay.ToString ' & ":" & System.DateTime.Now.Minute.ToString ' objWorksheet.PageSetup.PrintTitleRows End If objWorksheet.PrintPreview() On Error Resume Next MyXL.Visible = True MyXL.DisplayAlerts = True If ExcelWasNotRunning = True Then objWorksheet = Nothing MyXL.Application.Quit() End If 'Free up memory, otherwise there will be a memory leak. objWorksheet = Nothing objWorkbook = Nothing MyXL = Nothing 'Screen.MousePointer = vbDefault Exit Sub
closing out of excel seems to be causing a problem.
Excel has a known bug about closing down.
The attached code will force Excel to close.
The visible.false will not close excel, it is still running. You just can't see the interface, I was hoping it would switch back to AutoCAD when you tried it
Access a broad range of knowledge to help get the most out of your products and services.