Continue to Site

Eng-Tips is the largest engineering community on the Internet

Intelligent Work Forums for Engineering Professionals

  • Congratulations cowski on being selected by the Eng-Tips community for having the most helpful posts in the forums last week. Way to Go!

Excel Spread Sheet is locked while linked to SolidWorks

Status
Not open for further replies.

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(&quot;C:\Program Files\SolidWorks\Macros\Part_Number_Request_Form.xls&quot;)
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(&quot;Sheet1&quot;)

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
 
Replies continue below

Recommended for you

Bradley
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
 
William,
What is your e-mail address?

Bradley
 
I have gotten in trouble before for trying to post my Email on the forum.

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
 
You kind of lost me. Im not sure why the line:

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
 
Bradly,
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
 
WillOMalley,
No suggestions.

Bradley
 
You can place your email in these posts, but it is not recommended because of possible "discovery" by spam crawlers ... & to avoid being flamed if you upset someone. [evil]

Your best bet would be to place it in your profile but "encrypt" it in some way. See my profile for a simple example.

[cheers] from (the City of) Barrie, Ontario.

[lol] Everyone has a photographic memory. Some just don't have film. [lol]
 
Will,
Sent if off a few minutes ago. 6:40 a.m. California time.

Bradley
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor