Continue to Site

Eng-Tips is the largest engineering community on the Internet

Intelligent Work Forums for Engineering Professionals

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

is it possible to make an exe out of an VBA project? or to run a script outside de VB editor?

Status
Not open for further replies.

Aar0nr

New member
Aug 20, 2013
9
MX
Hi guys, i was wondering if a could make an exe out of an VBA project, since i couldn't run it from VBS by pasting the code directly into it,

- is there a way to run it outside the visual basic editor?
- should i buy VB6 and try to run it from there?

THANKs in advance.

here's my code

Code:
Sub CATmain()

'Declaracion de variables
Dim spabench As SPAWorkbench
Dim mymeas
Dim ref1 As Reference
Dim myans As Double
Dim InputObjectType(0)

'Devuelve el numero de caras de la parte
Set objsel = CATIA.ActiveDocument.Selection
objsel.Clear
objsel.Search "Type=Topology.Face,all"
MsgBox objsel.Count2
X = objsel.Count2

'**************CICLO***************
For i = 1 To 5 'Aqui va x


Set partDocument1 = CATIA.ActiveDocument
Set part1 = partDocument1.Part
Set Selection = partDocument1.Selection

Set ref1 = Selection.Item(i).Reference
Set spabench = partDocument1.GetWorkbench("SPAWorkbench")
Set mymeas = spabench.GetMeasurable(ref1)
Dim mycoord(2)
mymeas.GetCOG mycoord
MsgBox mycoord(0)
Next

'***********************************
End Sub

 
Replies continue below

Recommended for you

thanks ferdo, i will be looking a way to do it a post it.
 
A small modification in your code and it runs from CATScript. Still, you can show us how did you tried to run the macro not from vba editor.

Code:
Sub CATmain()

'Declaracion de variables
Dim spabench As SPAWorkbench
Dim mymeas
Dim ref1 As Reference
Dim myans As Double
Dim InputObjectType(0)

'Devuelve el numero de caras de la parte
Set objsel = CATIA.ActiveDocument.Selection
objsel.Clear
objsel.Search "Type=Topology.Face,all"
MsgBox objsel.Count2
X = objsel.Count2

'**************CICLO***************
For i = 1 To 5 'Aqui va x


Set partDocument1 = CATIA.ActiveDocument
Set part1 = partDocument1.Part
Set Selection = partDocument1.Selection

Set ref1 = Selection.Item(i).Reference
Set spabench = partDocument1.GetWorkbench("SPAWorkbench")
Set mymeas = spabench.GetMeasurable(ref1)
[highlight #D3D7CF]ReDim mycoord(2)[/highlight]
mymeas.GetCOG mycoord
[highlight #D3D7CF]MsgBox mycoord(0) & "    " & mycoord(1) & "    " & mycoord(2)[/highlight]
Next

'***********************************
End Sub

Regards
Fernando

 
it works now, apparently it is not neccesary to declare the variable type, as follows.

Code:
Sub CATmain()

'Declaracion de variables
[highlight #FCE94F]Dim spabench 
Dim mymeas
Dim ref1[/highlight] 
Dim myans 
Dim InputObjectType(0)

'Devuelve el numero de caras de la parte
Set objsel = CATIA.ActiveDocument.Selection
objsel.Clear
objsel.Search "Type=Topology.Face,all"
MsgBox objsel.Count2
X = objsel.Count2

'**************CICLO***************
For i = 1 To 5 'Aqui va x


Set partDocument1 = CATIA.ActiveDocument
Set part1 = partDocument1.Part
Set Selection = partDocument1.Selection

Set ref1 = Selection.Item(i).Reference
Set spabench = partDocument1.GetWorkbench("SPAWorkbench")
Set mymeas = spabench.GetMeasurable(ref1)
ReDim mycoord(2)
mymeas.GetCOG mycoord
MsgBox mycoord(0) & "    " & mycoord(1) & "    " & mycoord(2)
Next

'***********************************
End Sub

and it works from a macro .catvbs file outside VBA.

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Top