×
INTELLIGENT WORK FORUMS
FOR ENGINEERING PROFESSIONALS

Log In

Come Join Us!

Are you an
Engineering professional?
Join Eng-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!
  • Students Click Here

*Eng-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

Jobs

Excel Spread Sheet is locked while linked to SolidWorks

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

Bradley

RE: Excel Spread Sheet is locked while linked to SolidWorks

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

RE: Excel Spread Sheet is locked while linked to SolidWorks

(OP)
William,
   What is your e-mail address?

Bradley

RE: Excel Spread Sheet is locked while linked to SolidWorks

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

RE: Excel Spread Sheet is locked while linked to SolidWorks

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
    

RE: Excel Spread Sheet is locked while linked to SolidWorks

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

RE: Excel Spread Sheet is locked while linked to SolidWorks

(OP)
WillOMalley,
   No suggestions.

Bradley

RE: Excel Spread Sheet is locked while linked to SolidWorks

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.

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

from (the City of) Barrie, Ontario.

Everyone has a photographic memory. Some just don't have film.

RE: Excel Spread Sheet is locked while linked to SolidWorks

nic tip.. I will give it a try

Will

RE: Excel Spread Sheet is locked while linked to SolidWorks

(OP)
Will,
Sent if off a few minutes ago. 6:40 a.m. California time.

Bradley

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Eng-Tips Forums free from inappropriate posts.
The Eng-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Eng-Tips forums is a member-only feature.

Click Here to join Eng-Tips and talk with other members!


Resources