0

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?

RRUZ
  • 134,889
  • 20
  • 356
  • 483
V.Salles
  • 403
  • 2
  • 9
  • 16

1 Answers1

1

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.

David Heffernan
  • 601,492
  • 42
  • 1,072
  • 1,490