Advertisement

Run an Excel macro from Chemistation

Discussions about chromatography data systems, LIMS, controllers, computer issues and related topics.

4 posts Page 1 of 1
Does anyone knows how to run an Excel macro from Chemstation.
I am going to run a macro named “mytest” in an Excel file. Below is my code. I tried RunExcelMacro() function and DDEExecute, both of them did not work. My Chemstation version is D.01.02. Does anyone knows what is the problem? Thanks.

local excel$,myPath$,myFile$,MyString$

excel$="C:\Program Files\Microsoft Office\Office\excel.exe "
myPath$="c:\temp\"
myFile$="test.xls"

excel$=excel$ + myPath$+ myFile$
a=exec(excel$,2)

chan = ddeinitiate("excel"+val$(a), myFile$)
! DDEExecute chan, [RUN("Mytest")]
print RunExcelMacro(chan, "Mytest")

DDETerminate Chan ! Close the channel
Remove excel$,myPath$,myFile$,MyString$
I presume that version D.01.02 is the Mass Spec version of the ChemStation. I am only familiar with the GC version of the ChemStation. In the GC version, you need to address the 'system' in Excel to send commands. I have the following commands in a macro to control Excel

chan2=DDEInitiate("excel","system")
ddeexecute chan2,"[WORKBOOK.ACTIVATE(""Page 1"")]"
ddeexecute chan2,"[PRINT]"

You can try this, but please not the use of the '[' brackets, they have to be there.

Gasman
Thanks for your help. I am using Mass Spec version Chemstation.

However, it still not working when i copied your code. It gave a DDE error:26 message. Here is the log file:

Log file is C:\MSDChem\1\log.log. Logging is on
ELSE
ENDIF
RETURN
macro "runexcel",g
TEST
local excel$,myPath$,myFile$,MyString$
excel$="C:\Program Files\Microsoft Office\Office\excel.exe "
C:\Program Files\Microsoft Office\Office\excel.exe
myPath$="c:\temp\"
c:\temp\
myFile$="test.xls"
test.xls
excel$=excel$ + myPath$+ myFile$
C:\Program Files\Microsoft Office\Office\excel.exe c:\temp\test.xls
a=exec(excel$,2)
Executing: C:\Program Files\Microsoft Office\Office\excel.exe c:\temp\test.xls
Execution completed.
2168
chan2=DDEInitiate("excel","system")
2.81858e+009
ddeexecute chan2,"[WORKBOOK.ACTIVATE(""Page 1"")]"
9/13/2011 14:58:07
Macro: TEST, Cmd: ddeexecute chan2,"[WORKBOOK.ACTIVATE(""Page 1"")]"
Msg:
DDE error: 26


endlog
logging off
yorkflying,

I can not help you any further, as my experience is with GC ChemStation macros, and there is a big difference between the Mass Spec macro language and the GC macro language.

Gasman
4 posts Page 1 of 1

Who is online

In total there are 36 users online :: 0 registered, 0 hidden and 36 guests (based on users active over the past 5 minutes)
Most users ever online was 5108 on Wed Nov 05, 2025 8:51 pm

Users browsing this forum: No registered users and 36 guests

Latest Blog Posts from Separation Science

Separation Science offers free learning from the experts covering methods, applications, webinars, eSeminars, videos, tutorials for users of liquid chromatography, gas chromatography, mass spectrometry, sample preparation and related analytical techniques.

Subscribe to our eNewsletter with daily, weekly or monthly updates: Food & Beverage, Environmental, (Bio)Pharmaceutical, Bioclinical, Liquid Chromatography, Gas Chromatography and Mass Spectrometry.

Liquid Chromatography

Gas Chromatography

Mass Spectrometry