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
 All Forums
 Origin Forum for Programming
 LabTalk Forum
 Excel macro

Note: You must be registered in order to post a reply.
To register, click here. Registration is FREE!

Screensize:
UserName:
Password:
Anti-Spam Code:
Format Mode:
Format: BoldItalicizedUnderlineStrikethrough Align LeftCenteredAlign Right Horizontal Rule Insert HyperlinkUpload FileInsert Image Insert CodeInsert QuoteInsert List
   
Message:

* HTML is OFF
* Forum Code is ON
Smilies
Smile [:)] Big Smile [:D] Cool [8D] Blush [:I]
Tongue [:P] Evil [):] Wink [;)] Clown [:o)]
Black Eye [B)] Eight Ball [8] Frown [:(] Shy [8)]
Shocked [:0] Angry [:(!] Dead [xx(] Sleepy [|)]
Kisses [:X] Approve [^] Disapprove [V] Question [?]

 
Check here to subscribe to this topic.
   

T O P I C    R E V I E W
kdsaransh Posted - 03/27/2015 : 1:01:23 PM
Hi,

i am using origin 9.1 and i want to open an macro (.xlsm) in origin. Please suggest.....

thanks in advance.

Regards,
9   L A T E S T    R E P L I E S    (Newest First)
cracksnew Posted - 04/18/2015 : 02:10:07 AM
Facing Same Problem But have a great knowledge from this Post Thanks kdsarnash and all.
kdsaransh Posted - 04/17/2015 : 05:20:54 AM
Thanks a lot
SeanMao Posted - 04/07/2015 : 01:58:28 AM
Hi,

If your Macro is attached to a specific sheet, you have to use the following syntax instead:


excel.run(Sheet1.test) // Sheet1 is the sheet name where Macro  
                       // test is attached to


You can rewrite the code to fit your own situation.

Regards!

Sean

kdsaransh Posted - 04/03/2015 : 07:04:13 AM
Hello,

Many thanks for the help. It solved a lot of problem, but the results are updated in excel workbook not in the origin workbook. This macro when run, will result in two additional sheet apart from the original sheet. These two additional sheets are not updated in the origin workbook, but are there in the excel sheet.

Again many many thanks..
SeanMao Posted - 04/03/2015 : 04:29:52 AM
Hi,

You can run the following LabTalk scripts in Script Window or new an OGS script file:


	dlgfile gr:=*.xlsm mu:=1; // Open dialog to select XLSM file
	
	string path$ = fname$;
	
	impExcel excludeempty:=0; // Import Excel file without excluding empty sheets
	
	%B = %H;                  // Record current active window
	
	document -append %(path$); // Open the XLSM file inside Origin
	
	excel.run(test); // Run Macro with name "test" associated with XLSM file
	
	save -i; // Save the results in the external Excel file
	
	win -a %B; // Activate the Origin workbook that imported Excel sheets before
	
	reimport; // Re-import the data from newly updated Excel file
	          // to obtain data from running Macro


Those lines firstly import XLSM file into Origin, then it opens Excel workbook inside Origin as it is and run Excel macros using Excel program. After excel sheet obtained the results, the script then saved the results in that XLSM file.

Eventually, through "Re-import" feature the results via running Macros will be updated in Origin workbook.

Give it a try and see whether it works.

Regards!

Sean

OriginLab Tech. Service
kdsaransh Posted - 04/03/2015 : 01:32:27 AM
Hi,

Thanks for the reply, but its not clear to me.

I am posting a excel macro code as below. I have an excel file and the sheet name is IDVDInputVDD. Now i want to run this excel macro code in labtalk so that my output files are formed in origin itself.


Sub ExtractIDVDFromVDD()

Dim i, j, k As Long
Dim SourceSheetName, DestSheetName, DataType As String
Dim SourceVDColNo, SourceVGColNo, SourceIDColNo, SourceIGColNo, SourceVSDummyColNo, SourceVDDummyColNo As Integer
Dim VDStep, VGStep, VDStartValue, VDEndValue, VGStartValue, VGEndValue, W, L, Ls, Ld As Double
Dim DestVDColNo, DestVGColNo, DestIDColNo, DestIGColNo, DestVSDummyColNo, DestVDDummyColNo As Integer
Dim DestWColNo, DestLColNo, DestLsColNo, DestLdColNo, DestVSDummyAdjColNo As Integer
Dim NoofDestSheet, NoofRow As Integer

DataType = "Dark"
SourceSheetName = "IDVDInputVDD"
SourceVDColNo = 1
SourceVGColNo = 2
SourceIDColNo = 6
SourceIGColNo = 5
SourceISColNo = 7
SourceVDDummyColNo = 8
VDStep = -0.1
VGStep = 5
VDStartValue = 0
VDEndValue = -40
VGStartValue = -40
VGEndValue = 0
W = 0.1
L = 0.01
Ls = 0.01
Ld = 0.01

DestVDColNo = 1
DestIDColNo = 3
DestISColNo = 4
DestIGColNo = 2
DestVDDummyColNo = 5
DestWColNo = 10
DestLColNo = 11
DestLsColNo = 12
DestLdColNo = 13
DestVSDummyAdjColNo = 14

NoofVG = (VGEndValue - VGStartValue) / VGStep + 1
NoofRow = (VDEndValue - VDStartValue) / VDStep + 1

MsgBox ("NoofRow=" & NoofRow)

DestSheetNameForward = "IDVDDD_Forward_Origin"
DestSheetNameRev = "IDVDDD_Rev_Origin"

Application.DisplayAlerts = False
On Error Resume Next
Sheets(DestSheetNameForward).Delete
Application.DisplayAlerts = True
Sheets.Add().Name = DestSheetNameForward

Application.DisplayAlerts = False
On Error Resume Next
Sheets(DestSheetNameRev).Delete
Application.DisplayAlerts = True
Sheets.Add().Name = DestSheetNameRev

For i = 1 To NoofVG


Sheets(DestSheetNameForward).Cells(1, DestVDColNo + (i - 1) * 5).Value = "VD_" & (VGStartValue + VGStep * (i - 1)) * (-1) & "_DD_" & DataType & "_F"
Sheets(DestSheetNameForward).Cells(1, DestIGColNo + (i - 1) * 5).Value = "IG_" & (VGStartValue + VGStep * (i - 1)) * (-1) & "_DD_" & DataType & "_F"
Sheets(DestSheetNameForward).Cells(1, DestIDColNo + (i - 1) * 5).Value = "ID_" & (VGStartValue + VGStep * (i - 1)) * (-1) & "_DD_" & DataType & "_F"
Sheets(DestSheetNameForward).Cells(1, DestISColNo + (i - 1) * 5).Value = "IS_" & (VGStartValue + VGStep * (i - 1)) * (-1) & "_DD_" & DataType & "_F"
Sheets(DestSheetNameForward).Cells(1, DestVDDummyColNo + (i - 1) * 5).Value = "VdummyD_" & (VGStartValue + VGStep * (i - 1)) * (-1) & "_DD_" & DataType & "_F"

For j = 1 To NoofRow
Sheets(DestSheetNameForward).Cells(j + 1, DestVDColNo + (i - 1) * 5).Value = Sheets(SourceSheetName).Cells((i - 1) * 2 * NoofRow + j + 1, SourceVDColNo).Value
Sheets(DestSheetNameForward).Cells(j + 1, DestIGColNo + (i - 1) * 5).Value = Sheets(SourceSheetName).Cells((i - 1) * 2 * NoofRow + j + 1, SourceIGColNo).Value
Sheets(DestSheetNameForward).Cells(j + 1, DestIDColNo + (i - 1) * 5).Value = Sheets(SourceSheetName).Cells((i - 1) * 2 * NoofRow + j + 1, SourceIDColNo).Value
Sheets(DestSheetNameForward).Cells(j + 1, DestISColNo + (i - 1) * 5).Value = Sheets(SourceSheetName).Cells((i - 1) * 2 * NoofRow + j + 1, SourceISColNo).Value
Sheets(DestSheetNameForward).Cells(j + 1, DestVDDummyColNo + (i - 1) * 5).Value = Sheets(SourceSheetName).Cells((i - 1) * 2 * NoofRow + j + 1, SourceVDDummyColNo).Value
Next j

Sheets(DestSheetNameRev).Cells(1, DestVDColNo + (i - 1) * 5).Value = "VD_" & (VGStartValue + VGStep * (i - 1)) * (-1) & "_DD_" & DataType & "_R"
Sheets(DestSheetNameRev).Cells(1, DestIGColNo + (i - 1) * 5).Value = "IG_" & (VGStartValue + VGStep * (i - 1)) * (-1) & "_DD_" & DataType & "_R"
Sheets(DestSheetNameRev).Cells(1, DestIDColNo + (i - 1) * 5).Value = "ID_" & (VGStartValue + VGStep * (i - 1)) * (-1) & "_DD_" & DataType & "_R"
Sheets(DestSheetNameRev).Cells(1, DestISColNo + (i - 1) * 5).Value = "IS_" & (VGStartValue + VGStep * (i - 1)) * (-1) & "_DD_" & DataType & "_R"
Sheets(DestSheetNameRev).Cells(1, DestVDDummyColNo + (i - 1) * 5).Value = "VdummyD_" & (VGStartValue + VGStep * (i - 1)) * (-1) & "_DD_" & DataType & "_R"

For j = 1 To NoofRow
Sheets(DestSheetNameRev).Cells(j + 1, DestVDColNo + (i - 1) * 5).Value = Sheets(SourceSheetName).Cells((i - 1) * 2 * NoofRow + j + 1 + NoofRow, SourceVDColNo).Value
Sheets(DestSheetNameRev).Cells(j + 1, DestIGColNo + (i - 1) * 5).Value = Sheets(SourceSheetName).Cells((i - 1) * 2 * NoofRow + j + 1 + NoofRow, SourceIGColNo).Value
Sheets(DestSheetNameRev).Cells(j + 1, DestIDColNo + (i - 1) * 5).Value = Sheets(SourceSheetName).Cells((i - 1) * 2 * NoofRow + j + 1 + NoofRow, SourceIDColNo).Value
Sheets(DestSheetNameRev).Cells(j + 1, DestISColNo + (i - 1) * 5).Value = Sheets(SourceSheetName).Cells((i - 1) * 2 * NoofRow + j + 1 + NoofRow, SourceISColNo).Value
Sheets(DestSheetNameRev).Cells(j + 1, DestVDDummyColNo + (i - 1) * 5).Value = Sheets(SourceSheetName).Cells((i - 1) * 2 * NoofRow + j + 1 + NoofRow, SourceVDDummyColNo).Value
Next j

Next i
End Sub



Thanks and regards,
Rajesh Agarwal..

Echo_Chu Posted - 03/30/2015 : 06:02:07 AM
Hi,

To Run Excel Macros in Origin, you will need to open the external excel file in Origin instead of import it, for example


document -append D:\Test1.xlsm;


To run the macro, please use codes as below


Excel.RunRange(SheetName,RangeName,Arg1,Arg2,&ldots;,Arg5)


Echo
OriginLab
kdsaransh Posted - 03/29/2015 : 03:47:50 AM
hi,
Thanks,

Importing is not a problem, but the problem is how to run the code that i had written in excel macro in labtalk.

For example: i have an excel file and using excel macro i had done some analysis by writing a code in excel macro. Now i have to copy and paste the results obtained from excel to origin. but i simply want to import an excel file and run the macro code using labtalk in origin so that the results are there in the origin file itself.

I hope that i am clear.

Thanks once again....
lkb0221 Posted - 03/27/2015 : 2:13:37 PM
You can still use the same XF:
http://www.originlab.com/doc/X-Function/ref/impExcel

The Origin Forum © 2020 Originlab Corporation Go To Top Of Page
Snitz Forums 2000