Continue to Site

Eng-Tips is the largest engineering community on the Internet

Intelligent Work Forums for Engineering Professionals

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

Start excell from macro

Status
Not open for further replies.

BBRAZEAU

Mechanical
Jun 29, 2001
3
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. : )
 
Replies continue below

Recommended for you

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:
Code:
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.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor