I'm am currently working on something similar to this. So I feel your
pain.
A couple of points:
1. Change "Dim rRange as Range" to "Dim rRange as Word.Range" since the
the Range object exists in both Word and Excel. Your Set statement
should take care of any scope resolutions issues, but it's just a good
habit for the long term readability of the code.
2. Try xlsObject.Selection.Group before your xlsObject.Selection.Copy.
This will copy it as a single picture and should take care of the
stacking issues. Follow it with a xlsObject.Selection.Ungroup.
3. I really don't understand what you're trying to do here:
Set xlsObject = CreateObject("Excel.Application")
strFilename = xlsObject.GetOpenFilename()
If strFilename = "False" Then
MsgBox "Cancelled!"
Exit Sub
End If
xlsObject.Workbooks.Open FileName:=strFilename
To test if Excel is already open, and if not, create a new instance,
the code would look something like the following:
Dim wb As Excel.Workbook
On Error Resume Next
Set xlsObject = GetObject(, "Excel.Application")
If Err.Number = 429 Then
Set xlsObject = CreateObject("Excel.Application")
xlsObject.Visible = True
Else
Set wb = xlsObject.ActiveWorkbook
End If
Note that I added the "Dim wb as Excel.Workbook" line. With your
original code, I'm not sure what would happen if there were multiple
workbooks (Excel files) open. I think it would iterate through all the
sheets in all the open Excel files.
4. "If I run the macro it aborts after inserting one picture. If I
single step through the code it will add 35 pictures and then abort."
I get this problem all the time. Adding error handling certainly helps,
but I still see inconsistent behavior like this from time to time.
HTH,
Nick Hebb
BreezeTree Software, LLC
http://www.breezetree.com