To work around this problem, transform the XML before you
open it in Excel and omit the value for the
StyleSheets parameter. To do this, use Microsoft XML (MSXML) to load the XML
and XSL into
DOMDocument objects so that you can transform the XML at run time and save
the results to a file. The resulting file can then be opened in Excel without
user intervention.
Sub Macro3()
'Load the XML and the XSL (the stylesheet).
Dim oXML As Object, oXSL As Object
Set oXML = CreateObject("MSXML.DOMDocument")
Set oXSL = CreateObject("MSXML.DOMDocument")
oXML.Load "c:\customers.xml"
oXSL.Load "c:\customers.xsl"
'Transform the XML using the stylesheet.
Dim sHTML As String
sHTML = oXML.transformNode(oXSL)
'Save the results to an HTML file.
Open "c:\customers.htm" For Output As #1
Print #1, sHTML
Close #1
'Automate Excel to open the HTML file.
Dim oApp As Excel.Application
Set oApp = CreateObject("excel.application")
oApp.Visible = True
oApp.Workbooks.Open "c:\customers.htm"
End Sub