ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Type Mismatch Error (https://www.excelbanter.com/excel-programming/410148-type-mismatch-error.html)

Sarah (OGI)

Type Mismatch Error
 
I'm getting a type mismatch error, at the point of 'For Each pic In
wsSource.Pictures' in the following code - any ideas why this might be?

=============
Sub CopyAllPictures()
Dim r As Long, c As Long
Dim wsSource As Worksheet
Dim wsDest As Worksheet
Dim pic As Picture

Set wsSource = Workbooks("test.xls").Worksheets("Summary")
Set wsDest = Worksheets("PC (Chart)-NI-MONTH")

r = wsSource.Rows.Count
c = wsSource.Columns.Count

For Each pic In wsSource.Pictures
With pic.TopLeftCell
If .Row < r Then r = .Row
If .Column < c Then c = .Column
End With
Next

wsDest.Activate
wsDest.Cells(r, c).Activate

wsSource.Pictures.Copy
wsDest.Paste

wsDest.Cells(r, c).Activate



End Sub
============

[email protected]

Type Mismatch Error
 
Hi
I don't think worksheets or even workbooks have a picture object. Try
Shape in the Shapes class (this may pick up comments and buttons
however).

regards
Paul

On Apr 29, 12:14*pm, Sarah (OGI)
wrote:
I'm getting a type mismatch error, at the point of 'For Each pic In
wsSource.Pictures' in the following code - any ideas why this might be?

=============
Sub CopyAllPictures()
Dim r As Long, c As Long
Dim wsSource As Worksheet
Dim wsDest As Worksheet
Dim pic As Picture

Set wsSource = Workbooks("test.xls").Worksheets("Summary")
Set wsDest = Worksheets("PC (Chart)-NI-MONTH")

r = wsSource.Rows.Count
c = wsSource.Columns.Count

For Each pic In wsSource.Pictures
With pic.TopLeftCell
If .Row < r Then r = .Row
If .Column < c Then c = .Column
End With
Next

wsDest.Activate
wsDest.Cells(r, c).Activate

wsSource.Pictures.Copy
wsDest.Paste

wsDest.Cells(r, c).Activate

End Sub
============




All times are GMT +1. The time now is 05:54 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
ExcelBanter.com