×
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

Start excell from macro

Start excell from macro

Start excell from macro

(OP)
Greetings I have written a program in excell that creates parts in solidworks based on user input to a form in excell.
I would like to start this excell file with a macro button in solidworks.I have found an old post in this forum that had info on this.The thread said this code:
' ******************************************************************************
' C:\DOCUME~1\BBrazeau\LOCALS~1\Temp\swx1216\Macro1.swb - macro recorded on 12/20/01 by BBrazeau
' ******************************************************************************
Dim swApp As Object
Dim Part As Object
Dim boolstatus As Boolean
Dim longstatus As Long
Dim Annotation As Object
Dim Gtol As Object
Dim DatumTag As Object
Dim FeatureData As Object
Dim Feature As Object
Dim Component As Object
Dim Workbooks As Object
Dim Filename As Object
Sub main()
Set swApp = CreateObject("SldWorks.Application")
*    Workbooks.Open Filename:="C:\Book1.xls", ReadOnly:=True
*    Workbooks.Application.Visible = True
    'Change a cell
    Range("B2").FormulaR1C1 = sEqn
*    Workbooks.Close
End Sub

or at least the 3 lines Preceeded by"*" would do the trick,but when I run this macro I get "Object or withblock variable not set"
I have included the excell object libary in the macro under tools refs.
Any ideas? I would really like this macro to be able to open my excell file .It would give my program a polished feel. : )

RE: Start excell from macro

I see one problem right off the bat. First, you should not declare the Workbooks variable since it is reserved by the Excel Object library.

Note: This will be happening quite fast since the file is being closed after modification. You should also note that the ReadOnly property of the file will not permit saving any changes.

Try this:

Option Explicit

Dim swApp As Object

Sub main()
    Set swApp = CreateObject("SldWorks.Application")

    'Open the Workbook
    Workbooks.Open Filename:="C:\Book1.xls", ReadOnly:=False
    Workbooks.Application.Visible = True

    'Change a cell
    Range("B2").FormulaR1C1 = "Some Text"

    'Save and Close the Workbook
    ActiveWorkbook.Save
    Workbooks.Close
End Sub

Hope this helps!

DimensionalSolutions@Core.com
While I welcome e-mail messages, please post all thread activity in these forums for the benefit of all members.

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