Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

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

Translate Excel Macro into VFP code

Status
Not open for further replies.

dotnik

Programmer
Nov 14, 2003
24
IT
Hello,

I'm italian programmer and I live in Basilicata (South of Italy).
a) I must to create a excel document, as I can convert the following instructions generate from excel's macro into Visual Foxpro code?

* -------
Hts Macro
' Macro registrata il 22/09/2004 da Administrator

Application.CutCopyMode = False
Range("A29:H35").Select
Selection.Copy
Range("A36").Select
Selection.Insert Shift:=xlDown

b) There is a reference guide with a set of istruction that they can be used for automation with Word or Excel?

Very thanks

Nicola
 
a) Can you explain what "Selection.Insert Shift:=xlDown" is suppose to do?

Code:
#DEFINE xlDown -4121 
oExcel = createobject('excel.application')
oWb = oExcel.workbooks.open('myexcel.xls')
With oExcel
    .Application.CutCopyMode = .f.
    .Range("A29:H35").Select
    .Selection.Copy
    .Range("A36").Select
    .Selection.Insert Shift:=xlDown [COLOR=green][b]&& No translated[/b][/color]
Endwith

b)



Mike Gagnon

If you want to get the best response to a question, please check out FAQ184-2483 first.
 
I think the line that Mike could not translate should be (not sure though):

Code:
.Selection.insert( -4121 )
 
In visual basic there are two ways to pass parameters... Positional and Named. Positional is exactly the same as the way we pass parameters in VFP. Named however, is what you see with the Shift:=xldown (the ":=" is kind of stolen from pascal style coding). If VFP was able to do Named parameter passing it would be like this...

=MyFunc(tcVar:="Hello World")

Function MyFunc (tnVar, tdVar, tcVar)
return .t.
EndFunc

...essentially we would be only sending in one argument and it would be directed at the tcVar parameter. tnVar and tdVar would not be passed, however since VFP only allows positional passing of parameters we have to make that call like...

=MyFunc(0, {}, "Hello World")

...this way VFP knows that tcVar gets the value of "Hello World".

So, in order to know how to translate the Visual Basic insert method call we have to know the syntax of it, in order to know what if any parameters were before the Shift parameter in position. In this case I believe Stefan5627 has already provided the answer given that the Selection in this case is a Range Object there is only one parameter, the Shift parameter. Had the object been a Character Object instead then the parameter would have been a String. Which is why I believe the pass-by name syntax was used in this case, the VBA developer is trying to distinguish between the Range Object insert method and the Characters and ShapeNodes collection objects that also have a insert method, not because there was any particular reason that pass-by name had to be used.

boyd.gif

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top