I'm trying to open a Excel workbook and run a macro in it, but the macro is localized in another workbook, like this:
Excel := CreateOleObject('Excel.Application');
Excel.Workbooks.Open('C:\Documents and Settings\Administrator\MyDocs\2013\JUN\andrade 1670930.xml');
Excel.Run('C:\Configura_Xml.xls!Configura_XML_Geral');
Excel.Quit;
But this code doesn't work because the syntax for running a macro is:
"'C:\Name_Of_Book'!Name_of_Macro"
How do I do it in Delphi?
Your question boils down to this:
How do I specify a single quote character in a Delphi string?
You do that by escaping the quote like this:
''
So, to specify a string containing a single quote surrounded by spaces, say, you write this:
str := ' '' ';
To run your macro you quote it like this:
Excel.Run('''C:\Configura_Xml.xls''!Configura_XML_Geral');
The full details can be found in the documentation .
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.