Standing
Mechanical
- Jan 14, 2002
- 1,578
I have written a Visual Basic 6 program to read SolidWorks 2003 SP5.1 custom properties. The same program opens Excel 2000 and puts the properties onto a form. SolidWorks is running and the Excel form is shown on the screen I cannot print the Excel form. If I click on SolidWorks then back to Excel worksheet I can print. Do you know of a way to get focus back to Excel so I can print in one step?
Here is how I start Excel:
Option Explicit
Dim oXLExcel As Excel.Application
Dim oWB As Excel.Workbook ' Declare an object variable.
Dim oWS As Excel.Worksheet
Dim oExcel As Object
Private Sub RunForm()
Set oWB = GetObject("C:\Program Files\SolidWorks\Macros\Part_Number_Request_Form.xls"
On Error Resume Next ' Defer error trapping.
Set oExcel = GetObject("C:\Program Files\Microsoft Office\Office\Excel.Application"
If Err.Number <> 0 Then ExcelWasNotRunning = True
Err.Clear ' Clear Err object in case error occurred.
Set oExcel = GetObject("C:\Program Files\SolidWorks\Macros\Part_Number_Request_Form.xls"
oExcel.Application.Visible = True
oExcel.Parent.Windows(1).Visible = True
oExcel.Visible = True ' <-- ** Optional **
oExcel.DisplayAlerts = False ' <-- 'oExcel' instead of 'Application'.
Set oWB = oExcel.Workbooks.Add
Set oWS = oWB.Worksheets("Sheet1"
And this is how I end Excel:
Private Sub Exit_Here()
Set oExcel = Nothing
Set oWB = Nothing
Set oWS = Nothing
Set frmPartNumberForm = Nothing
Unload Me
End
End Sub
Bradley
Here is how I start Excel:
Option Explicit
Dim oXLExcel As Excel.Application
Dim oWB As Excel.Workbook ' Declare an object variable.
Dim oWS As Excel.Worksheet
Dim oExcel As Object
Private Sub RunForm()
Set oWB = GetObject("C:\Program Files\SolidWorks\Macros\Part_Number_Request_Form.xls"
On Error Resume Next ' Defer error trapping.
Set oExcel = GetObject("C:\Program Files\Microsoft Office\Office\Excel.Application"
If Err.Number <> 0 Then ExcelWasNotRunning = True
Err.Clear ' Clear Err object in case error occurred.
Set oExcel = GetObject("C:\Program Files\SolidWorks\Macros\Part_Number_Request_Form.xls"
oExcel.Application.Visible = True
oExcel.Parent.Windows(1).Visible = True
oExcel.Visible = True ' <-- ** Optional **
oExcel.DisplayAlerts = False ' <-- 'oExcel' instead of 'Application'.
Set oWB = oExcel.Workbooks.Add
Set oWS = oWB.Worksheets("Sheet1"
And this is how I end Excel:
Private Sub Exit_Here()
Set oExcel = Nothing
Set oWB = Nothing
Set oWS = Nothing
Set frmPartNumberForm = Nothing
Unload Me
End
End Sub
Bradley