Few questions about VB

A

artmajster

1. How can I do number for example 812 from 812,033217 ?

I try to do like this but it did not work

Dim first as double
Dim second as intiger

firs = 812,033217
second = first
first = second

but still firs = 812,033217 :confused:

2. How can I open not .xls file from VB code wrote in Excel file

I want to open Solid Works file "example.SLDPRT" in Solid Works o
course


thx for any suggestio
 
B

BrianB

I guess you are not un the UK. It would be a help if you show you
"Location" in your personal profile.

1. Probably because you have not spelled it correctly (grin). Thi
works as expected for me :-
'------------------------------
Sub test()
Dim First As Double
Dim Second As Integer
First = 812.03 ' we use a dot for decimals in UK
Second = First
First = Second
MsgBox (First)
End Sub
'------------------------------
or you could use :-
Second = Int(First)
'------------------------------

2. Here is an example of use of Shell from VB Editor Help to open th
Calculator application (also see SendKeys).
'-------------------------------------------------------
RetVal = Shell("C:\WINDOWS\CALC.EXE", 1)
'-------------------------------------------------------
To open a specific file you will need to check if/how your applicatio
uses command line variables. Perhaps just a space between the .EXE an
filename will do. something like :-

'----------------------------------------------------------------------------
Retval = Shell("C:\MYPATH\SOLID.EXE D:\PATH\MYFILE.SLDPRT",1)
'---------------------------------------------------------------------------
 
A

artmajster

Second = Int(First) works great :)

@BrianB
I use dot in VB of course ( I didn't copy, but write code in first pos
) :)

Ad.2
I'll check this :rolleyes
 
A

artmajster

New problem

I have two files firs.xls and second.xls

and I have in first.xls file function in Modules

function call ()
dim helper

helper = write_me_something ()
end function


in second.xls file function in Modules

function write_me_something ()
msgbox " something "
end function

This isn't work unfortunately :(

Is it posible to do something like that ?
 
A

artmajster

Ad. 2

done :)

pomocna = Shell("D:\Program Files\SolidWorks\sldworks.ex
F:\yea\zbiornik.SLDASM", 1)


Ad. 3

forget about it ;)


Ad. 4

I'm still trying, but I can't do this :(

HELP please :
 
D

Dave Peterson

I put these two procedures in book2.xls:

Option Explicit

Function callMeNow() As Variant
Dim helper As Variant
helper = Application.Run("book1.xls!write_me_something", "I'm off")
callMeNow = helper
End Function

Sub test01()
MsgBox callMeNow
End Sub

And in book1.xls, I put this function:
Option Explicit
Function write_me_something(myParm As Variant) As Variant
write_me_something = myParm & " and now I'm back"
End Function


======
Another way to do it is to add a reference in book2.xls (calling workbook) to
book1.xls (called workbook).

You'd have to change the project name from VBAProject to something more
meaningful (book1Proj) and then you could use that function in book1 just like
it was built into VBA.

Click on the VBAProject that should be renamed and then hit F4 (to see the
properties window). Change VBAProject there.

Then your routines would boil down to:

Option Explicit
Function callMeNow() As Variant
Dim helper As Variant
helper = write_me_something("i'm off")
callMeNow = helper
End Function
Sub test01()
MsgBox callMeNow
End Sub


=======
I changed the name of your function. Call is a nice VBA term. And I think it's
better not to reuse them. It may work, but it confuses the heck out of me.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top