Closing Objects

G

gb0dms

I am inserting excel charts and .ppt pages into word
it seems to be hanging after we run these macros
I do have some code for closing the doc's but am I still missing something?

Sub xyScatter()
Charts "S:\CORPFIN\!Template\Memo\Graphics\xy Scatter.xls"
End Sub

Sub GraphicSmall()
Charts "S:\CORPFIN\!Template\Memo\Graphics\GraphicSmall.ppt"
End Sub

Sub Charts(File As String)

If Selection.Information(wdWithInTable) = True Then
Selection.InlineShapes.AddOLEObject , FileName:=File, LinkToFile:=False

'Clear objects
Set InlineShapes = Nothing
Set AppExcel = Nothing
Set AppPowerpoint = Nothing
Set OLEObject = Nothing


Else
MsgBox "Your insertion point is not inside a table."
End If

End Sub
 
G

George Lee

It’s hard to say with this little amount of code. It could be something in
those files, charts, or presentations. Accessing an S drive is typically a
mapped one, so the drive could be unavailable, or on a slow network.

In general, however, it’s not a good idea to close or clear objects like
that. It’s best to close them in the same routine that they’re opened in. At
the same time, check to see if there are not any more opened documents by
that application, then close the application before setting it’s object to
nothing, or else you might be making people lose their documents
unexpectedly. Finally, always use OPTION EXPLICIT to make sure the object is
defined ahead of time. It does make problem solving easier.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top