Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Apport from newbie to newbie: VBA trought QM
#1
First you must have an Excel object to work with, you can create it or refer to a workbook already open.
This example creates it:
Code:
Copy      Help
typelib Excel
Excel.Application a._create
Excel.Workbook b=a.Workbooks.Add()
ExcelSheet es.ws=b.Worksheets.Item(1)
es.Activate(4) ;;activate Excel
es.ws.Application.Sheets.Item(1).Name = "Plan de Trabajo y Retorno del C"
int w=win("" "XLMAIN")
max w
str f.expandpath("$desktop$\test45.xls")
del f; err
b.SaveAs(f @ @ @ @ @ 1)
es.ws.Application.ActiveWindow.Zoom=85

This example focus and activate an Excel already open:
Code:
Copy      Help
Excel.Workbook x._getfile("$desktop$\test45.xls")
Excel.Application a=x.Application
ExcelSheet es.ws=x.Worksheets.Item(1)
a.Visible=TRUE; err
Excel.Windows ws=a.Windows
Excel.Window w=ws.Item(1)
w.Visible=TRUE
int w1=win("Microsoft Excel - test45.xls" "XLMAIN")
act w1

define and print last row with data:
Code:
Copy      Help
int ultima_fila = es.ws.Application.ActiveSheet.Range("A1").End(xlDown).Row
out ultima_fila

data dummy and select:
Code:
Copy      Help
es.ws.Application.ActiveSheet.Range("A1:A5").Value = "XXX YYY ZZZ"
int ultima_fila    = es.ws.Application.ActiveSheet.Range("A1").End(xlDown).Row
es.ws.Application.ActiveSheet.Range(F"A1:A{ultima_fila}").Select


To work with VBA functions that needs arguments, is necessary to input the Enum Value insted of Enum Name, for example the Enum Value -4163 = the Enum Name xlPasteValues, the Enum Value -4142 = Enum Name xlNone.
copy and paste only values:
Code:
Copy      Help
es.ws.Application.Selection.copy
es.ws.Application.Range("E1").PasteSpecial(-4163,-4142,,)

Last piece code line should be the translate this VBA code:
Code:
Copy      Help
Selection.Copy
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks:=False, Transpose:=False

Best Regards


Forum Jump:


Users browsing this thread: 1 Guest(s)