L
lee hite
i'm trying to update an Excel sheet that is within an embedded object
in a Word document, and am running in to problems with how things are
specified while working with Excel from within Word. below is a
simplified example of what i'm doing. everything works exactly the
way it's supposed to -- but the problem i have run in to is that in
order for the code to run reliably, i must close all open instances of
both Word and Excel before this code is processed. otherwise, i get
seemingly random errors -- sometimes the Word instance which is
running invisible will mysteriously become visible, and at other times
the Excel instance will crash. but there's no rhyme or reason to this
-- i can't replicate anything. and as i said, if i close all
instances before this particular code is run, then re-start those
instances, everything works fine. but i'm taking a significant
performance hit having to continually open and close applications and
files, which i would like to avoid.
any help/suggestions appreciated! here's the relevant code:
Dim objShape as Object
dim objEmbedded as Object
If wdApp.ActiveDocument.InlineShapes.Count Then
Set objShape = wdApp.ActiveDocument.InlineShapes(1)
Else
Set objShape = wdApp.ActiveDocument.Shapes(1)
End If
objShape.OLEFormat.Open
Set objEmbedded = objShape.OLEFormat.object
With objEmbedded.Sheets(2)
For intKntr = 1 To intTotSpecs
strChartCell = strCellSpec(intKntr)
vntCellVal = vntCellData(intKntr)
.Range(strChartCell).Value = vntCellVal
Next intKntr
End With
objEmbedded.Application.Quit
Set objEmbedded = Nothing
in a Word document, and am running in to problems with how things are
specified while working with Excel from within Word. below is a
simplified example of what i'm doing. everything works exactly the
way it's supposed to -- but the problem i have run in to is that in
order for the code to run reliably, i must close all open instances of
both Word and Excel before this code is processed. otherwise, i get
seemingly random errors -- sometimes the Word instance which is
running invisible will mysteriously become visible, and at other times
the Excel instance will crash. but there's no rhyme or reason to this
-- i can't replicate anything. and as i said, if i close all
instances before this particular code is run, then re-start those
instances, everything works fine. but i'm taking a significant
performance hit having to continually open and close applications and
files, which i would like to avoid.
any help/suggestions appreciated! here's the relevant code:
Dim objShape as Object
dim objEmbedded as Object
If wdApp.ActiveDocument.InlineShapes.Count Then
Set objShape = wdApp.ActiveDocument.InlineShapes(1)
Else
Set objShape = wdApp.ActiveDocument.Shapes(1)
End If
objShape.OLEFormat.Open
Set objEmbedded = objShape.OLEFormat.object
With objEmbedded.Sheets(2)
For intKntr = 1 To intTotSpecs
strChartCell = strCellSpec(intKntr)
vntCellVal = vntCellData(intKntr)
.Range(strChartCell).Value = vntCellVal
Next intKntr
End With
objEmbedded.Application.Quit
Set objEmbedded = Nothing