Excel Spread Sheet is locked while linked to SolidWorks
Excel Spread Sheet is locked while linked to SolidWorks
(OP)
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
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






RE: Excel Spread Sheet is locked while linked to SolidWorks
A few questions if I may..
First let me say that I am sorry but I do not have an answer to your question. However,I am a programmer and have just gotten asked to write a little code for Solidworks.
I see that you have code to export data from your Drawing to an external excel spread sheet. I was wondering if you would be willing to share some of the code that you used to do that?
I would like to take the Temp Excel file that is created by Solidworks and export it to a database.
Thanks for any help.
William O'Malley
RE: Excel Spread Sheet is locked while linked to SolidWorks
What is your e-mail address?
Bradley
RE: Excel Spread Sheet is locked while linked to SolidWorks
I get home around 5:30pm Eastern standard time NY
my Yahoo Instant Messenger screen name is will_omalley. My AOL Instant messenger screen name is chaos14235
look for me if you have either one..
thanks
will
RE: Excel Spread Sheet is locked while linked to SolidWorks
Set oExcel = GetObject("C:\Program Files\Microsoft Office\Office\Excel.Application")
should work on your box. And depending on how the rest of the code flows, you may NOT be cleaning up the objects you created. Try the following base snippet. It looks as though you are already using an Excel Reference in your VBA code.
Make sure to replace the "WorkBookFileSpec" Constant with a path/file to one of your actual .xls files.
' --- snip ---------------------
Sub Test
Const WorkBookFileSpec As String = "c:\Book1.xls"
Dim xlApp As Excel.Application
Dim xlBook As Excel.Workbook
Dim xlSheet As Excel.Worksheet
Set xlApp = New Excel.Application
xlApp.Visible = True
Set xlBook = xlApp.Workbooks.Open(WorkBookFileSpec)
Set xlSheet = xlApp.ActiveSheet
xlSheet.PrintOut
xlBook.Close False
xlApp.Quit
Set xlSheet = Nothing
Set xlBook = Nothing
Set xlApp = Nothing
End Sub
RE: Excel Spread Sheet is locked while linked to SolidWorks
I would still like to talk to you sometime. As I can't post my email address on this forum. Do you have a suggestion?
Thanks
Will
RE: Excel Spread Sheet is locked while linked to SolidWorks
No suggestions.
Bradley
RE: Excel Spread Sheet is locked while linked to SolidWorks
Your best bet would be to place it in your profile but "encrypt" it in some way. See my profile for a simple example.
RE: Excel Spread Sheet is locked while linked to SolidWorks
Will
RE: Excel Spread Sheet is locked while linked to SolidWorks
Sent if off a few minutes ago. 6:40 a.m. California time.
Bradley