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. : )
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
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.