The Origin Forum
File Exchange
Try Origin for Free
The Origin Forum
Home | Profile | Register | Active Topics | Members | Search | FAQ | Send File to Tech support
Username:
Password:
Save Password
Forgot your Password? | Admin Options

 All Forums
 Origin Forum for Programming
 Forum for Automation Server/COM and LabVIEW
 Excel VBA - copy range & execute labtalk script
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic Lock Topic Edit Topic Delete Topic New Topic Reply to Topic

psoso

3 Posts

Posted - 07/29/2018 :  3:54:06 PM  Show Profile  Edit Topic  Reply with Quote  View user's IP address  Delete Topic
Origin Ver. and Service Release (Select Help-->About Origin): 9.1
Operating System: winxp

while being an absolute beginner isn't very helpful at all, I am still taken aback how I can't even get simple tutorial copies to work:

beginner project: from an open excel sheet, copy a range of strings into a new book in a new origin project. then run a labtalk script, save and exit.

While I can select my excel range, I cannot assign it to a variable that I can then insert into the origin range.

I also just cannot get the labtalk script to run with what I think should work.

Dim org As Origin.Application
Dim orgWkBk As Origin.WorksheetPage
Dim orgWks As Origin.Worksheet
Dim strPathName As Variant
Dim rangeexcel As Excel.range
Dim rangeori As Origin.DataRange

sheetname = ActiveSheet.Name
Range("c3", ActiveSheet.Range("c3").End(xlDown)).Select

' Create the Origin COM object, folder wkbk sheet and column works fine
Set org = New Origin.Application
org.NewProject
org.Execute ("sec -poc 1.5")
org.RootFolder.Folders.Add("Folder1").Activate 'add new folder
Set orgWkBk = org.WorksheetPages.Add
Set orgWks = orgWkBk.Layers(0)
orgWks.Columns.Add



Set rangeori = Wks.NewDataRange(0, 1)
rangeori.SetData = (ActiveSheet.range("c3", ActiveSheet.range("c3").End(xlDown)).Select)


org.Execute (name_of_custom_labtalkscript)


'saving also works
strPathName = Application.GetSaveAsFilename(sheetname, "Project files (*.OPJ),*.OPJ", 0)
org.Save (strPathName)
org.Execute ("sec -poc 1.5")
org.Exit

End Sub


Edited by - psoso on 07/29/2018 3:56:11 PM

YimingChen

1606 Posts

Posted - 08/01/2018 :  4:48:45 PM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
Hi Psoso,

Can you try the following script to set excel range to a variable and copy that into Origin worksheet. Please make sure [Book1]Sheet1 exists in Origin :


    Set rngDataAndParam = ActiveSheet.Range("c3", ActiveSheet.Range("c3").End(xlDown))
    pws = app.PutWorksheet("[Book1]Sheet1", rngDataAndParam.Value)


Please also check the webpage:
https://www.originlab.com/doc/COM/Classes/Application/PutWorksheet

Thank,

James
Go to Top of Page

psoso

3 Posts

Posted - 08/09/2018 :  3:30:19 PM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
thank you. with the additional help of some of the examples in the /SAMPLES folder I think I have ranges figured out.
I still don't understand the limitations of the execute command.
https://www.originlab.com/doc/COM/Classes/Application/Execute
In origin I have made a custom labtalk script many lines long (variable definitions, IFs and loops etc.) and would like to start it via vba.
Documentation makes it sound like it should work like:
app.Execute (name_of_custom_labtalkscript).
However, I can only get single x-functions to work this way.
I just assumed it would work similar to "excel.run(name_of_customexcelmacro)" ?
Go to Top of Page
  Previous Topic Topic Next Topic Lock Topic Edit Topic Delete Topic New Topic Reply to Topic
 New Topic  Reply to Topic
 Printer Friendly
Jump To:
The Origin Forum © 2020 Originlab Corporation Go To Top Of Page
Snitz Forums 2000