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
 LabTalk Forum
 Excel macro
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic Lock Topic Edit Topic Delete Topic New Topic Reply to Topic

kdsaransh

India
89 Posts

Posted - 03/27/2015 :  1:01:23 PM  Show Profile  Edit Topic  Reply with Quote  View user's IP address  Delete Topic
Hi,

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

thanks in advance.

Regards,

lkb0221

China
497 Posts

Posted - 03/27/2015 :  2:13:37 PM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
You can still use the same XF:
http://www.originlab.com/doc/X-Function/ref/impExcel
Go to Top of Page

kdsaransh

India
89 Posts

Posted - 03/29/2015 :  03:47:50 AM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
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....
Go to Top of Page

Echo_Chu

China
Posts

Posted - 03/30/2015 :  06:02:07 AM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
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
Go to Top of Page

kdsaransh

India
89 Posts

Posted - 04/03/2015 :  01:32:27 AM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
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..

Go to Top of Page

SeanMao

China
288 Posts

Posted - 04/03/2015 :  04:29:52 AM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
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
Go to Top of Page

kdsaransh

India
89 Posts

Posted - 04/03/2015 :  07:04:13 AM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
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..
Go to Top of Page

SeanMao

China
288 Posts

Posted - 04/07/2015 :  01:58:28 AM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
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

Go to Top of Page

kdsaransh

India
89 Posts

Posted - 04/17/2015 :  05:20:54 AM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
Thanks a lot
Go to Top of Page

cracksnew

India
1 Posts

Posted - 04/18/2015 :  02:10:07 AM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
Facing Same Problem But have a great knowledge from this Post Thanks kdsarnash and all.
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